2

I use OS X Mountain 10.8.2.

I used Automator and added AppleScript, copying the command from the old app's developer at the Iconoodle - Convenient ICNS to PNG image conversion (Iconoodle isn't supported by OS X 10.8 by being a PPC app). I saved the workflow as an application. I selected the images and dropped them into the application, but the images weren't converted to ICNS. I also copied from the question Convert image to .icns file AppleScript Obj-C and it didn't work either.

I'm really frustrated with it. I want to use Automator to convert the multiple images from PNG to ICNS once at all. It's very annoying to convert each image to ICNS in the icon editor applications, one for one. The Preview.app doesn't want to convert the image in format PNG to ICNS because it has only one page, it can convert it to ICNS only if the icon has many pages.

Do you know to make it?

Thank you for your attention, help and patience!

Community
  • 1
  • 1

2 Answers2

0

You can still run the iconoodle script by just pasting it to AppleScript Editor. It's just a wrapper for sips, but it can only convert icns to png.

You can use sips directly to convert png to icns:

for f in *.png; do sips -s format icns "$f" --out "${f%png}icns"; done
Lri
  • 26,768
  • 8
  • 84
  • 82
  • `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` Is it correct? –  Nov 26 '12 at 11:43
  • The command in the answer can just be run in Terminal. You have to give the actual paths as arguments: `do shell script "sips -s format icns " & quoted form of pngpath & " --out " & quoted form of icnspath`. – Lri Nov 26 '12 at 12:07
  • When I copied `do shell script "sips -s format icns " & quoted form of pngpath & " --out " & quoted form of icnspath`, Automator warned an error: **Syntax Error - The variable pngpath is not defined.** I also copied `for f in *.png; do sips -s format icns "$f" --out "${f%png}icns"; done` and Automator warned again the error: **A parameter name can’t go here.**. –  Nov 26 '12 at 12:16
0

Here is another approach... NOTE: Your ORIGINAL pngs will be scaled to the expected size before the icns file is created. If you want to keep a copy of the original png, duplicate it first. You can also add a line or so to the script to do so automatically.

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
adayzdone
  • 11,120
  • 2
  • 20
  • 37
  • Thank you a lot! It worked very well when I selected the multiple images. –  Nov 27 '12 at 06:41