如何命令Automator将多个图像从PNG转换为ICNS一次?

时间:2012-11-26 05:51:37

标签: png applescript converter automator icns

我使用OS X Mountain 10.8.2。

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

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

你知道吗?

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

2 个答案:

答案 0 :(得分:0)

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

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

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

答案 1 :(得分:0)

这是另一种方法...... 注意:在创建icns文件之前,您的ORIGINAL 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