Convert ICNS files with sips

Mac OS X application icons are stored within the application bundle in something called the Apple icon format. (If you download icons, you might find that some are stored in the .icns format as well.) The Apple icon format file extension is .icns, and these files can be opened (and converted to other formats) using Preview. So if you were giving a talk, for instance, and wanted to include a number of icons for the applications you were discussing, you could convert them using this process.

Find the application in the Finder, Control-click on it, then choose Show Package Contents from the pop-up menu. Navigate into Contents -> Resources and double-click the file you find there whose name ends in .icns (typically, it will be Dictionary.icns, Safari.icns, etc.). Preview should open, and you can then use File -> Save As to save it whatever format (using the pop-up menu) and location you prefer.

So that’s one way to do it. Here’s another that uses Terminal and a really useful program called sips that Apple included in OS X 10.3 and later. I covered sips briefly in the March 2005 Mac OS X Hints column. Basically, it’s a command-line tool for working with image files. While “command line” and “working with image files” may seem oxymoronic, that’s not necessarily the case. sips lets you do a ton of image processing; pretty much anything that doesn’t require you to actually see and manipulate the image can be handled by sips. For instance, sips can embed color profiles, flip, crop, pad, resample, rotate, and even create Finder icons for image files. You can read about everything you can do with sips by typing a few things in Terminal: man sips gets you the full help package, sips --help gives you a condensed version, and sips --helpProperties explains the various properties you can use with some sips commands.

But in all of that help, not once will you read that sips can work with .icns files. But it can. So as an alternative method of converting .icns files to other formats, you could do this in Terminal (using Dictionary as an example):

	$ cd /Applications/Dictionary.app/Contents/Resources

$ sips -s format png Dictionary.icns --out ~/Desktop/Dictionary_icon.png

The -s option tells sips to set a property for the image file; in this case, that’s the format property, and the value of that property is png. Instead of using png, you could also specify any of the other image formats sips supports: jpeg, tiff, gif, jp2, pict, bmp, qtif, psd, sgi, or tga.)

The --out bit tells sips where to store the converted file. In this case, the specified path points to the user’s desktop, and the file will be named Dictionary_icon.png.

Even though it’s not documented, sips will work with .icns files, as today’s hint demonstrates. But the bigger hint here is that sips can be used to do all sorts of image manipulation—and there may be times (this example not necessarily being one) where it’s faster and easier to use Terminal than it is to do the same thing in your favorite graphics editor.

Shop Tech Products at Amazon