【问题标题】:AppleScript icon resolutionAppleScript 图标分辨率
【发布时间】:2019-10-01 14:12:25
【问题描述】:

我可以在不同的地方找到如何个性化 AppleScript 图标: https://apple.stackexchange.com/questions/8299/how-do-i-make-an-applescript-file-into-a-mac-app Customize Applescript app icon

Apple 还谈到了常规 Xcode 应用程序中不同图标的分辨率: https://developer.apple.com/library/archive/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Optimizing/Optimizing.html

但是 AppleScript 图标应用的推荐分辨率是多少?

【问题讨论】:

  • 默认的 applet.icns 是一个低分辨率,包含 4 个图像 1,每个图像 1 为 256 x 256、128 x 128、32 x 32 和 16 x 16,所有图像均为 72 像素/英寸。至于推荐什么,我会参考您在问题中链接的 Apple 官方文档。

标签: icons applescript


【解决方案1】:

如果您在 Finder 中右键单击应用程序文件并选择“显示包内容”选项如果您打开其 .icns 文件(通常位于资源文件夹中),使用预览应用程序,使用侧边栏中的缩略图视图,您会注意到文件中包含同一个图标的多个版本。每个都有不同的尺寸和分辨率(1024 x 1024,每英寸 144 像素,512 x 512,每英寸 72 像素,等等……)

我很确定系统会根据情况决定使用哪个版本和大小的嵌入图标。例如,Dock 中使用的图标大小将大于应用程序运行时打开的文档所使用的图标。

如果您只想在 Finder 的获取信息窗口中使用 .png 文件更改 AppleScript 小程序的图标。 256 x 256,每英寸 72 像素应该没问题。

【讨论】:

  • 我一直在寻找可以从 png 转换为 icns 的应用程序,但我认为,它们都不能包含多个版本的 img。你知道有什么程序可以做到这一点吗?我使用 Inkscape 和 Gimp,它们无法转换为 ecns
  • 您可以使用两个命令行实用程序:iconutiltiff2icns。第二种只是将 tiff 文件转换为单项 icns 文件;第二个将 .iconset 对象(基本上是图像文件夹)转换为 .icns 文件。我所做的是在某处找到一个 .icns 文件,将其转换为图标集,使用命令行工具 sips 或图像处理应用程序将图标集中的所有图像替换为我之前的图像的适当大小版本使用,然后将图标重新转换回 icns。我想我可以写一个脚本来做这件事。给我一点,然后在下面检查我的答案。
【解决方案2】:

图标大小由系统使用,而不是由 AppleScript 使用,因此系统对“常规”应用程序所需的任何约定也应用于 AppleScript 应用程序。

编辑

根据其他答案之一的 cmets,这里有一个脚本,它将创建一个 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 解释为有意义的字符,这可能会引发错误。我在一个包含括号的文件名上注意到了这一点,但没有添加任何错误检查。
  • 此脚本不保留纵横比,因此如果您输入非正方形的图像,它会产生失真。如果您想保留纵横比,请记住图标必须是方形的,因此您必须先通过裁剪或填充来使图像方形。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-20
    • 2011-04-07
    相关资源
    最近更新 更多