Quick and dirty script to make Icons for macOS

Sometimes you just need a quick icon for your app.  You don't need anything fancy.  You cobble together something quick, then realize you need to save 10 copies of if and remember the syntax to create a .icns file, or drag each one into Xcode separately.  Or maybe find one of those online services that do it for free but sign you up their mailing list.

If none of that appeals to you, here is a quick (and extremely dirty) bash script that will do it for you in a second or two.  It's dead-simple, no fancy tricks and you should have the requirements pre-installed if you have a Mac and Xcode.  

Drop the code in a .sh file and chmod a+x it... it takes one parameter, the path to a .png file.  It should be at least 1536x1536 and should be square.  No error-checking of any kind is performed.

It uses the following 3 utilities that you probably have installed: 

  • sed for a quick regex
  • sips to do the image resizing
  • iconutil to make the .icns file

I'm sure you can improve on it, but I spent more time writing this post about it than I did writing the script, and it suits me just fine!

Hope it saves you some googling and time on stack overflow ; )

 

 

#!/bin/bash
infile=$(echo "$1" | sed -E 's/\.png//g')
echo "Making icons for $infile"

mkdir icon.iconset

sips $1 -Z 1024 --out icon.iconset/icon_512x512@2x.png
sips $1 -Z 512 --out icon.iconset/icon_512x512.png
sips $1 -Z 512 --out icon.iconset/icon_256x256@2x.png
sips $1 -Z 256 --out icon.iconset/icon_256x256.png
sips $1 -Z 256 --out icon.iconset/icon_128x128@2x.png
sips $1 -Z 128 --out icon.iconset/icon_128x128.png
sips $1 -Z 64 --out icon.iconset/icon_32x32@2x.png
sips $1 -Z 32 --out icon.iconset/icon_32x32.png
sips $1 -Z 32 --out icon.iconset/icon_16x16@2x.png
sips $1 -Z 16 --out icon.iconset/icon_16x16.png

sips $1 -Z 512 --out iTunesArtwork@1x.png
sips $1 -Z 1024 --out iTunesArtwork@2x.png
sips $1 -Z 1536 --out iTunesArtwork@3x.png

iconutil -c icns icon.iconset

Tags ,