This site runs best with JavaScript enabled.

PNG to ICNS Conversion Script and MacOS Automation

There are no special tools required to convert a PNG file to and ICNS file. Just use this simple script.

MacOS comes with the tools you need to convert PNG files to ICNS files. So here is a little script that will help you convert quickly.

First, the script:

5echo "Converting $1 to $ICON_NAME..."
7# Create an icon directory to work in
9mkdir $ICONS_DIR
11# Create all other images sizes
12sips -z 1024 1024 $1 --out "$ICONS_DIR/icon_512x512@2x.png"
13sips -z 512 512 "$ICONS_DIR/icon_512x512@2x.png" --out "$ICONS_DIR/icon_512x512.png"
14sips -z 512 512 "$ICONS_DIR/icon_512x512@2x.png" --out "$ICONS_DIR/icon_256x256@2x.png"
15sips -z 256 256 "$ICONS_DIR/icon_512x512@2x.png" --out "$ICONS_DIR/icon_256x256x.png"
16sips -z 256 256 "$ICONS_DIR/icon_512x512@2x.png" --out "$ICONS_DIR/icon_128x128@2x.png"
17sips -z 128 128 "$ICONS_DIR/icon_512x512@2x.png" --out "$ICONS_DIR/icon_128x128.png"
18sips -z 64 64 "$ICONS_DIR/icon_512x512@2x.png" --out "$ICONS_DIR/icon_64x64.png"
19sips -z 32 32 "$ICONS_DIR/icon_512x512@2x.png" --out "$ICONS_DIR/icon_32x32.png"
20sips -z 32 32 "$ICONS_DIR/icon_512x512@2x.png" --out "$ICONS_DIR/icon_16x16@2x.png"
21sips -z 16 16 "$ICONS_DIR/icon_512x512@2x.png" --out "$ICONS_DIR/icon_16x16.png"
23# Create the icns file
24iconutil -c icns $ICONS_DIR
26# remove the temporary directory
27rm -rf $ICONS_DIR
29# rename icns
30mv tempicon.icns $ICON_NAME

Save this script as png2icns and make it executable (chmod +x png2icns). Put this file in a directory listed in your system PATH.

Now, you can simply run the command from any directory in your terminal like so: png2icns exampleimage.png. It will then generate a new file named exampleimage.icns.

Let's take it a step further so you can also run the command by right-clicking on a png image in your finder. If you don't want to go set this up manually, you can download and import my workflow here.

Open Automator and create a new quick action. Set the following options in the screenshot below:

Quick Action screenshot

Add the Run Shell Script action. I used /bin/sh as my script. You will need to pass input as arguments.

Then just paste in the script above and save the workflow as "PNG to ICNS" (or whatever you prefer).

You should now be able to right-click on an image and select Quick Action -> PNG to ICNS. Your icns file should show up in your folder.

Workflow example gif

Discuss on TwitterEdit post on GitHub

Share article
Dustin Davis

Dustin Davis is a software engineer, people manager, hacker, and entreprenuer. He loves to develop systems and automation. He lives with his wife and five kids in Utah.

Join the Newsletter

Dustin Davis