24

I have an application that I've bundled into a Mac OS X app bundle. Everything is working fine, but I want to change its icon from the default. How do I set its icon? Thanks.

Walt D
  • 4,491
  • 6
  • 33
  • 43

3 Answers3

29

in your info.plist add

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

with icon file iconfile.icns in your Resources directory

cobbal
  • 69,903
  • 20
  • 143
  • 156
  • 10
    The answer is correct but the Finder doesn't usually pick up the change in the icon immediately. Copy the bundle to another folder to get it to register the new icon. – koan Jan 30 '11 at 16:03
  • 1
    I had to additionally remove empty Icon? file at the root of bundle. – ciastek Jan 05 '12 at 14:41
  • @ciastek im having the same issue, i replaced the iconfile.icns but im not able to get it to update the icon. can you please give me steps on how to find and remove empty icon please. – Noitidart Jan 13 '15 at 16:34
  • 1
    @koan is copying to another folder the only way? – Noitidart Jan 13 '15 at 16:36
  • 1
    @Noitidart Try re-registering your application with Launch Services: `/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -f /Applications/MyTool.app` – koan Jan 15 '15 at 21:35
  • It din't work @koan :( I got the image to take by creating a folder in the same folder of the Contents folder in the app. But my app icon doesn't stay associated with it: Can you please advise: http://stackoverflow.com/questions/730748/how-to-change-the-executable-in-an-os-x-application-bundle/731227#comment44255830_731227 – Noitidart Jan 16 '15 at 01:47
  • This doesn't work for me on Mojave, even after moving the bundle and running `lsregister` – Elliott B Sep 10 '20 at 19:26
  • It should be `iconfile.icns`, i.e. including the extension – Andy May 24 '22 at 10:09
8

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
4

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.
sage
  • 4,863
  • 2
  • 44
  • 47
  • Brilliant, this is just what I needed (and now have a custom Emacs GUI launcher which inherits all my .bashrc settings too, so I can find the aliases and other scripts readily from an emacs shell or eshell). – Ben Dec 31 '14 at 08:26