Changing a file’s icon in Mac OS X in 5 easy steps

A couple of days ago, I came across the problem that I wanted to be able to set the icon of a file that I was going to open under OS X independently of the application that was going to be used to open it. This seemed like a fairly trivial task, but it turned out that there were a few steps I needed to go through to make this happen.

The first thing that I needed to know was that, on a Mac running OS X, an icon can be up to 128 x 128 pixels in size and is able to have alpha transparency so that the background behind it is able to partially (or completely) show through. As well as the 128 x 128 version of the icon you can also provide extra, different sized, icons although in this instance I’ll only be talking about providing the biggest 128 x 128 pixel version – if you do this then OS X will automatically resample down for you to the smaller sizes it can show.

Following on from this, the next thing I needed to know was that an “icon file� in OS X is actually a collection of images all rolled up into one file. This collection isn’t editable in a normal image editor – instead you need to use something special such as Iconographer. For my purposes though, Iconographer turned out to be more than I needed. Instead, I grabbed myself a copy of img2icns, a little application that you simply drag an image onto which is then spat back out again at you in icns form. Just what I needed.

So, I created myself a nice little 128 x 128 png, with a nice bit of alpha transparency going on in the background, and I threw it at img2icns which happily created me a brand new icns file. Then, all I needed to do was actually apply this new set of icons to the file I wanted changing and I’d be done.

To do this, I brought up the “Get Info� window for the icns file I’d just created. Then, I clicked on the icon at the top left of this window and pressed command-c to copy it. Once I’d done this I brought up the “Get Info� window for the file whose icon needed changing, clicked on the icon at the top left of its window and pressed command-v to paste the icon over the top.

And that was all there was to it – simple once you know how.

So, to recap:

  1. Create a 128 x128 pixel image (preferably a PNG with some nice transparencies) to use as your icon.
  2. Convert the image to an icns file using img2icns by dragging your image onto the img2icns icon on your dock.
  3. Bring up the “Get Info� window for the icns file you just created, click on the preview of the icon at the top left of the window and then press command-c to copy it.
  4. Finally, bring up the “Get Info� window for the file that wants its icon changing, click on the icon at the top left of this window and press command-v.
  5. That’s it, job done! From now on, that file will show the icon you just selected. Ain’t life grand?

Oh, and if you ever decide that you made a mistake by changing that icon to something new you can always easily revert back to the original one instead. All you need do is bring up the file’s “Get Info� window, click on the icon in the top left and press delete. As if by magic, the file will once again use its original icon. Hooray!

permalink | View blog reactions

other relevant pages

about wwm

workingwith.me.uk is a resource for web developers created by Neil Crosby, a web developer who lives and works in London, England. More about the site.

Neil Crosby now blogs at The Code Train and also runs NeilCrosby.com, The Ten Word Review and Everything is Rubbish.