【问题标题】:How do I command Automator to convert the multiple images from PNG to ICNS once at all?如何命令 Automator 一次将多个图像从 PNG 转换为 ICNS?
【发布时间】:2012-11-26 05:51:37
【问题描述】:

我使用 OS X Mountain 10.8.2。

我使用 Automator 并添加了 AppleScript,从旧应用程序的开发人员处复制命令,地址为 Iconoodle - Convenient ICNS to PNG image conversion(OS X 10.8 不支持 Iconoodle,因为它是 PPC 应用程序)。我将工作流程保存为应用程序。我选择了图像并将它们放入应用程序,但图像没有转换为 ICNS。我也复制了Convert image to .icns file AppleScript Obj-C这个问题,也没有用。

我真的很沮丧。我想使用 Automator 将多个图像从 PNG 转换为 ICNS 一次。在图标编辑器应用程序中将每个图像转换为 ICNS 非常烦人,一对一。 Preview.app 不想将 PNG 格式的图像转换为 ICNS,因为它只有一页,只有当图标有很多页时,它才能将其转换为 ICNS。

你知道怎么做吗?

感谢您的关注、帮助和耐心!

【问题讨论】:

    标签: png applescript converter automator icns


    【解决方案1】:

    这是另一种方法... 注意:在创建 icns 文件之前,您的原始 png 将被缩放到预期的大小。如果要保留原始 png 的副本,请先复制它。您还可以在脚本中添加一行左右以自动执行此操作。

    property expectedSizes : {16, 32, 48, 128, 256, 512, 1024, 9999999}
    
    set myFiles to choose file with multiple selections allowed
    
    repeat with aFile in myFiles
    
        tell application "System Events" to set bPath to POSIX path of (container of aFile)
        set newPath to bPath & "/" & bName(aFile) & ".icns" as text
        set aFile to quoted form of (POSIX path of aFile)
    
        set {W, H} to {paragraph 1, paragraph 2} of (do shell script "sips -g pixelWidth -g pixelHeight " & aFile & " | grep -Eo [0-9]*$")
        set {W, H} to {W as number, H as number}
    
        if W > H then
            set W to eSize(W)
            do shell script "sips " & aFile & " -Z " & W & " -p " & W & space & W & " --padColor FFFFFF -i"
            delay 1
        else if H > W then
            set H to eSize(H)
            do shell script "sips " & aFile & " -Z " & H & " -p " & H & space & H & " --padColor FFFFFF -i"
            delay 1
            -- H = W but not in expected sizes
        else if H is not in expectedSizes then
            set H to eSize(H)
            do shell script "sips " & aFile & " -Z " & H & " -p " & H & space & H & " --padColor FFFFFF -i"
            delay 1
        end if
    
        do shell script "sips -s format icns " & aFile & " --out " & quoted form of newPath
    end repeat
    
    on bName(theFile)
        tell application "Finder" to set {name:fileName, name extension:nameExtension} to theFile
        set baseName to text 1 thru ((get offset of "." & nameExtension in fileName) - 1) of fileName
    end bName
    
    on eSize(lDimen)
        repeat with i from 1 to 8
            if lDimen < item i of expectedSizes then return item (i - 1) of expectedSizes
        end repeat
    end eSize
    

    【讨论】:

    • 非常感谢!当我选择多张图片时效果很好。
    【解决方案2】:

    您仍然可以通过将 iconoodle 脚本粘贴到 AppleScript Editor 来运行它。它只是 sips 的包装器,但它只能将 icns 转换为 png。

    您可以直接使用sips将png转换为icns:

    for f in *.png; do sips -s format icns "$f" --out "${f%png}icns"; done
    

    【讨论】:

    • on png2icns (pngpath, icnspath) set command to ("sips -s format icns "$f" --out "${f%png}icns") as «class utf8» do shell script command end png2icns 对吗?
    • 答案中的命令只能在终端中运行。您必须提供实际路径作为参数:do shell script "sips -s format icns " &amp; quoted form of pngpath &amp; " --out " &amp; quoted form of icnspath.
    • 当我复制 do shell script "sips -s format icns " &amp; quoted form of pngpath &amp; " --out " &amp; quoted form of icnspath 时,Automator 警告错误:语法错误 - 未定义变量 pngpath。 我还复制了 for f in *.png; do sips -s format icns "$f" --out "${f%png}icns"; done,Automator 再次警告错误: 参数名称不能放在这里。.
    猜你喜欢
    • 2020-12-22
    • 2011-05-27
    • 2016-03-22
    • 1970-01-01
    • 1970-01-01
    • 2017-12-21
    • 2010-10-21
    • 2012-08-13
    • 2019-08-05
    相关资源
    最近更新 更多