How do I set the icon for my application's Mac OS X app bundle?

in your info.plist add

<key>CFBundleIconFile</key>
<string>iconfile</string>

with icon file iconfile.icns in your Resources directory


I made a small script that takes a big image and resizes it to all expected icon sizes for Mac OS, including the double ones for retina displays. It takes the original png file, which I expect to be as big as the maximum size, if not bigger, to make sure they are rendered at maximum quality.

It resizes and copies them to a icon set, and uses the Mac OS's 'iconutil' tool to join them into a .icns file.

For this script to run, you need your original icon file to be a png, and you have your bundle in more or less working order. You only need to touch the first three lines.

export PROJECT=Myproject
export ICONDIR=$PROJECT.app/Contents/Resources/$PROJECT.iconset
export ORIGICON=Mybigfile.png

mkdir $ICONDIR

# Normal screen icons
for SIZE in 16 32 64 128 256 512; do
sips -z $SIZE $SIZE $ORIGICON --out $ICONDIR/icon_${SIZE}x${SIZE}.png ;
done

# Retina display icons
for SIZE in 32 64 256 512; do
sips -z $SIZE $SIZE $ORIGICON --out $ICONDIR/icon_$(expr $SIZE / 2)x$(expr $SIZE / 2)x2.png ;
done

# Make a multi-resolution Icon
iconutil -c icns -o $PROJECT.app/Contents/Resources/$PROJECT.icns $ICONDIR
rm -rf $ICONDIR #it is useless now

If you came here because you have a single app and want to change the image on your computer only (not sure how it works for sharing), there are much easier ways. In particular, here are two options I have used:

  1. If you want to copy an existing icon:

    • Select the source item and press Cmd-I (Apple-I)
    • Select the item you want to change and press Cmd-I (Apple-I)
    • Drag the icon from the source to the top left icon of the one you want to change (the example image shows the target icon: it is the 'folder' icon to the left of the words "bird_id 2"): enter image description here
  2. Create a .icns file from any image. If you use MacPorts, I recommend instead using the port makeicns - see below for more info. You can alternatively do this using an app such as http://www.img2icnsapp.com/ as recommended at https://discussions.apple.com/thread/2773825.

makeicns v1.4.10 (284bd686824f)

Usage: makeicns [k1=v1] [k2=v2] ...

Keys and values include:
    512: Name of input image for 512x512 variant of icon
    256: Name of input image for 256x256 variant of icon
    128: Name of input image for 128x128 variant of icon
     32: Name of input image for 32x32 variant of icon
     16: Name of input image for 16x16 variant of icon
     in: Name of input image for all variants not having an explicit name
    out: Name of output file, defaults to first nonempty input name,
         but with icns extension

  align: [center, left, right, top, bottom] {First letter suffices!}

Examples:

  makeicns -512 image.png -32 image.png
      Creates image.icns with only a 512x512 and a 32x32 variant.

  makeicns -in myfile.jpg -32 otherfile.png -out outfile.icns
      Creates outfile.icns with sizes 512, 256, 128, and 16 containing data
      from myfile.jpg and with size 32 containing data from otherfile.png.

Tags:

Macos