AppleScript 图标分辨率
AppleScript icon resolution
我可以在不同的地方找到如何个性化 AppleScript 图标:
https://apple.stackexchange.com/questions/8299/how-do-i-make-an-applescript-file-into-a-mac-app
Apple 还谈到了常规 Xcode 应用程序中不同图标的分辨率:
https://developer.apple.com/library/archive/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Optimizing/Optimizing.html
但是 AppleScript 图标应用程序的推荐分辨率是多少?
图标大小由系统使用,而不是由 AppleScript 使用,因此系统对 'regular' 应用程序需要的任何约定也应该用于 AppleScript 应用程序。
编辑
根据对其他答案之一的评论,这里有一个脚本,可以根据您选择的任何图像创建一个包含所有建议大小的 icns 文件:
set picFile to choose file with prompt "Choose an image to iconize." of type {"public.image"}
set workingFolder to POSIX path of (path to temporary items from user domain)
set outputFolder to POSIX path of (path to desktop from user domain)
set sizesList to {16, 32, 128, 256, 512}
tell application "System Events"
set pictureFilePath to quoted form of (get POSIX path of picFile)
set {pictureName, ext} to {name, name extension} of picFile
if ext is not "" then
set pictureName to text 1 through -((length of ext) + 2) of pictureName
end if
-- create iconset folder
set iconsetFolder to make new folder at folder workingFolder with properties {name:pictureName & ".iconset"}
-- cycle through sizes to create normal and hi-def sized icon images
repeat with thisSize in sizesList
set iconFilePath to POSIX path of iconsetFolder & "/" & my makeFileNameFromSize(thisSize, false)
do shell script "sips -z " & thisSize & " " & thisSize & " " & "-s format png " & pictureFilePath & " --out " & iconFilePath
set iconFilePath to POSIX path of iconsetFolder & "/" & my makeFileNameFromSize(thisSize, true)
do shell script "sips -z " & thisSize * 2 & " " & thisSize * 2 & " " & "-s format png " & pictureFilePath & " --out " & iconFilePath
end repeat
-- create new icns file
set iconsetPath to quoted form of (POSIX path of iconsetFolder as text)
set outputPath to quoted form of (outputFolder & pictureName & ".icns")
do shell script "iconutil -c icns -o " & outputPath & " " & iconsetPath
end tell
on makeFileNameFromSize(s, x2)
set fileName to "icon_" & s & "x" & s
if x2 then set fileName to fileName & "@2x"
set fileName to fileName & ".png"
return fileName
end makeFileNameFromSize
注意事项:
- 这会将icns文件放在桌面上;可以通过更改
outputFolder
变量来更改。
- 如果图像文件名中存在 shell 解释为有意义的字符,这可能会引发错误。我在一个包含括号的文件名上注意到了这一点,但没有添加任何错误检查。
- 此脚本不保留宽高比,因此如果您为其提供非正方形的图像,则会产生失真。如果您想保留宽高比,请记住图标必须是正方形的,因此您必须先通过裁剪或填充来使图像正方形。
如果您在 Finder 中右键单击一个应用程序文件并选择“显示包内容”选项如果您打开它的 .icns 文件(通常位于资源文件夹中),使用预览应用程序,使用缩略图视图在边栏中,您会注意到在文件中,包含同一图标的多个版本。每一个都有不同的尺寸和分辨率(1024 x 1024 每英寸 144 像素,512 x 512 每英寸 72 像素,等等)
我很确定系统会根据情况决定使用哪个版本和大小的嵌入式图标。例如,在 运行.
时,Dock 中使用的图标大小将大于应用程序打开的文档中使用的图标
如果您只想在 Finder 的获取信息 window 中使用 .png 文件更改 AppleScript 小程序的图标。 256 x 256 每英寸 72 像素应该没问题。
我可以在不同的地方找到如何个性化 AppleScript 图标:
https://apple.stackexchange.com/questions/8299/how-do-i-make-an-applescript-file-into-a-mac-app
Apple 还谈到了常规 Xcode 应用程序中不同图标的分辨率: https://developer.apple.com/library/archive/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Optimizing/Optimizing.html
但是 AppleScript 图标应用程序的推荐分辨率是多少?
图标大小由系统使用,而不是由 AppleScript 使用,因此系统对 'regular' 应用程序需要的任何约定也应该用于 AppleScript 应用程序。
编辑
根据对其他答案之一的评论,这里有一个脚本,可以根据您选择的任何图像创建一个包含所有建议大小的 icns 文件:
set picFile to choose file with prompt "Choose an image to iconize." of type {"public.image"}
set workingFolder to POSIX path of (path to temporary items from user domain)
set outputFolder to POSIX path of (path to desktop from user domain)
set sizesList to {16, 32, 128, 256, 512}
tell application "System Events"
set pictureFilePath to quoted form of (get POSIX path of picFile)
set {pictureName, ext} to {name, name extension} of picFile
if ext is not "" then
set pictureName to text 1 through -((length of ext) + 2) of pictureName
end if
-- create iconset folder
set iconsetFolder to make new folder at folder workingFolder with properties {name:pictureName & ".iconset"}
-- cycle through sizes to create normal and hi-def sized icon images
repeat with thisSize in sizesList
set iconFilePath to POSIX path of iconsetFolder & "/" & my makeFileNameFromSize(thisSize, false)
do shell script "sips -z " & thisSize & " " & thisSize & " " & "-s format png " & pictureFilePath & " --out " & iconFilePath
set iconFilePath to POSIX path of iconsetFolder & "/" & my makeFileNameFromSize(thisSize, true)
do shell script "sips -z " & thisSize * 2 & " " & thisSize * 2 & " " & "-s format png " & pictureFilePath & " --out " & iconFilePath
end repeat
-- create new icns file
set iconsetPath to quoted form of (POSIX path of iconsetFolder as text)
set outputPath to quoted form of (outputFolder & pictureName & ".icns")
do shell script "iconutil -c icns -o " & outputPath & " " & iconsetPath
end tell
on makeFileNameFromSize(s, x2)
set fileName to "icon_" & s & "x" & s
if x2 then set fileName to fileName & "@2x"
set fileName to fileName & ".png"
return fileName
end makeFileNameFromSize
注意事项:
- 这会将icns文件放在桌面上;可以通过更改
outputFolder
变量来更改。 - 如果图像文件名中存在 shell 解释为有意义的字符,这可能会引发错误。我在一个包含括号的文件名上注意到了这一点,但没有添加任何错误检查。
- 此脚本不保留宽高比,因此如果您为其提供非正方形的图像,则会产生失真。如果您想保留宽高比,请记住图标必须是正方形的,因此您必须先通过裁剪或填充来使图像正方形。
如果您在 Finder 中右键单击一个应用程序文件并选择“显示包内容”选项如果您打开它的 .icns 文件(通常位于资源文件夹中),使用预览应用程序,使用缩略图视图在边栏中,您会注意到在文件中,包含同一图标的多个版本。每一个都有不同的尺寸和分辨率(1024 x 1024 每英寸 144 像素,512 x 512 每英寸 72 像素,等等)
我很确定系统会根据情况决定使用哪个版本和大小的嵌入式图标。例如,在 运行.
时,Dock 中使用的图标大小将大于应用程序打开的文档中使用的图标如果您只想在 Finder 的获取信息 window 中使用 .png 文件更改 AppleScript 小程序的图标。 256 x 256 每英寸 72 像素应该没问题。