icons - AppleScript 图标分辨率
问题描述
我可以在不同的地方找到如何个性化 AppleScript 图标: https : //apple.stackexchange.com/questions/8299/how-do-i-make-an-applescript-file-into-a-mac-app 自定义 Applescript应用程序图标
Apple 还谈到了常规 Xcode 应用程序中不同图标的分辨率: https ://developer.apple.com/library/archive/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Optimizing/Optimizing.html
但是 AppleScript 图标应用程序的推荐分辨率是多少?
解决方案
图标大小由系统使用,而不是由 AppleScript 使用,因此系统对“常规”应用程序所需的任何约定也应该用于 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 解释为有意义的字符,这可能会引发错误。我在包含括号的文件名上注意到了这一点,但没有添加任何错误检查。
- 这个脚本不保留纵横比,所以如果你给它一个不是正方形的图像,它会产生失真。如果您想保留纵横比,请记住图标必须是方形的,因此您必须首先通过裁剪或填充来使图像方形。
推荐阅读
- laravel - 数据未保存在数据库中
- json - delphi json数组中[和{的区别是什么
- c# - 从 Facebook 链接获取用户全名
- apache-kafka - WSO2 Micro Integrator 是否支持 Kafka 2.3.1 Inbound Endpoint 从 Kafka 读取消息?
- primes - 整数的初始因子数为 O(log(n))
- python - pycharm中的库导入问题
- laravel - 如何在 laravel 中使用增量函数
- docker - VS Code 容器远程扩展:无法获取远程环境
- three.js - THREE.js 在模型缩放而不是拉伸时使纹理重复
- r - data.frame - 对象不能被强制输入'double'