Customizing file and folder icons in Mac OS X
Customizing the appearance of files and folders in OS X is a cinch. ⌘C, ⌘I, ⌘V, punctuated by a few mouse clicks.
Actually, that's total bullshit.
Sure, in the simplest of cases the copy and paste approach gets the job done, assuming one knows to copy from Preview.app if copying from the original source fails. As soon as one decides to do something a bit more advanced, such as providing versions for display at different sizes, one's shit outta luck.
Creating .icns and applying them to files, folders, or bundles
-

Create icon versions at one or more of the following sizes: 16, 32, 128, 256, and 512. (I've created two very different images for this tutorial.)


Save the images in a lossless format such as PNG. (If saving from Photoshop, make sure to use Save for Web & Devices. Icon Composer doesn't like PNG files generated via Photoshop's Save / Save As.)

-

Open Icon Composer, located in /Developer/Applications/Utilities. This is part of the Apple Developer Tools, which are free to download from Apple. If you're bandwidth-conscious you can dig out your Mac OS X installation DVD to save yourself a few GBs.

- Icon Composer interface
Copy and paste the various versions into their respective slots. (The foolproof way to copy an icon is to open it in Preview, ⌘A to select, then ⌘C to copy.)
Save the Icon Composer file. This'll create a single .icns file containing all the different versions you included.
-

The final step is to apply attach the .icns file as metadata to the file, folder, or bundle of interest. There are a plethora of apps which provide this functionality via attractive GUIs, but one shouldn't need third-party software to change the appearance of a folder!
I scoured the Web for a way to edit this metadata directly. I failed to find one, but came across the next best thing: a shell script written and kindly shared by Damien Bobillot. Download setfileicon.gz then crack open Terminal.app, located in /Applications/Utilities.
In Terminal, navigate to your Downloads folder (or wherever you saved the script).
$ cd ~/Downloads $ ls
Run the
lscommand to inspect the contents of the directory. If you used Safari to download the script, you should see a file namedsetfileicon. If you used another browser you'll likely seesetfileicon.gz; unzip it by double-clicking the file in Finder.Make the script executable and move it to your /bin directory so that it can be run from any directory (you'll be asked to enter your password).
$ chmod 555 setfileicon $ sudo mv setfileicon /bin/setfileicon
Finally, run the script passing in two arguments: the path to the .icns file; and the path to the file, folder, or bundle to which you'd like to attach the icons.
$ setfileicon ~/icons.icns ~/example
TL;DR
I agree. It shouldn't be this difficult. At least I've now documented the convoluted process. :s

- Icons in situ (note the 16x16 icon in the sidebar)
Possibly related posts
- Accessing MySQL shell via Terminal
- Faster Terminal navigation via aliases
- Customizing your bash prompt for pleasure and profit
- Show full directory path in Finder window title bar
- Fascinating insight into the mind of a Windows user
Comments
Overcoming my fear of running random downloaded code from the internet, I tried this, and it worked perfectly!
Thanks!
Note that you can use it without any typing by opening a terminal window and dragging in
- setfileicon
- the .icns file
- the thing you want to show up with that icon
For this typing-free approach, it doesn't need to be in /bin.
I'm pleased to hear that it worked for you, Matt. Thanks for the tip about the sudo-free approach!
Here is a simple way I find:
- open the .icns file in Preview;
- cmd+a then cmd+c
- the folder that you want to change icon ->"get info"
- click the icon on the up left corner then cmd+v.
It works for me :).
After reading your comment, Ryan, I opened an .icns file in Preview and did a "select all" on the sidebar items. My hope was that all the icons would be copied to the clipboard. Unfortunately, pasting over the folder icon in the "get info" window applied just one of the icons to the folder.
Your technique is certainly a good one when dynamically scaling a 512x512 icon is appropriate, but it doesn't handle cases in which different icons are required in differing contexts.
I found a much easier way to do this WITHOUT terminal or an Icon changing app! Simply download Fluid (www.fluidapp.com - "Fluid lets you create a Site Specific Browser (SSB) out of any website or web application, effectively turning your favorite web apps into desktop apps.") So create an app with any website, use your .icns file you want for your REAL app and hit Create. Then just like Apple says, Click Get Info of your random app and copy the icon and paste it into your desired icon! Simple! (And delete the Fluid app :P) It is a rather silly method but easier then using Terminal, at least for me since I have no clue whatsoever on how to use it!!!
It works for me :)
How do you extract the icon (ie: the icns resource) from an existing folder? I tried to do Command+C with the "Downloads" folder's "Get Info" window, but all I see in Preview is just a scaled down version of the 512x512 icon, not the green download 16x16 icon anywhere in there.
I'm not aware of any way to access a folder's .icns resource. I do know that one can right-click on an application in Finder, select Show Package Contents, and dig around in Contents/Resources to find its .icns file.
If you have a custom folder icon it shows up as a file named "icon", which is hidden.
Finally i have found the the ⌘C, ⌘I, ⌘V solution! Whenever you downloaded .icns file, it's automatically open by 'Preview' right? just ⌘C any one of the size at thumbnails, ⌘I to the folder/file you wanted to place and ⌘V at the top left corner original icon, that it!!
The cmd-i cmd-c cmd-v approach is all very well if you are working inside the Mac OS GUI but I need to do it from the Terminal Console for a few different reasons which I won't go into right now.
I was hoping the setfileicon would allow me to do this but I ran it and nothing happened. I am wondering if this is because I haven't installed the Developer Tools yet? When I say nothing happened I mean that it did not create a '.VolumeIcon.icns' file in the selected volume.
I have tried a number of different ways to move/copy '.VolumeIcon.icns' into the revelant volume but the .icns file is not recognised. I know that the file is working because I copied it from another volume.
This is when I came across the posts about metadata, and it seems that a reference to '.VolumeIcon.icns' is stored somewhere in '.DS_Store', so simply copying or moving '.VolumeIcon.icns' is not enough. I have tried moving/copying both files together and it still doesn't recognise the file.
I am assuming that the '.DS_Store' file is unique to each volume and is overwritten almost immediately by Mac OS. I also tried changing the ownerships/permissions but it made no difference.
Please let me know if you have anymore advice for me.
I'm certainly no expert. I wonder, though, whether Mac OS X treats volume icons differently from file and folder icons (Damien states that his script can "modify the icon of a file or folder").
@ryan's method works very well.
But I want also be able to use that folder icons when I drag folder shortcuts to the dock… After I change icons for the folders, I drag them to dock and default folder icon is visible. I want to assign custom folder icons such as Applications, Downloads have.
Any ideas?
I encountered a little oddness while playing around with the script, I believe it can only change the icon for a folder if that folder is empty or something like that. Does that sound right?
I wasn't able to change the icon on the folder I wanted to using the script, but when I created a new folder, I could change the icon on that. Which I was then able to copy via the info windows to the eventual target folder.
S.
I don't recall running into that issue, Shane. Thanks for sharing your workaround.
Thanks for finding this David.
I had a disc corruption problem which caused Finder to crash when I opened my Documents directory.
From the terminal, I copied the contents, folder by folder, into a new directory, renamed both directories, so that my newly created directory was now Documents. After I had done a disc repair I deleted the old directory. Bad mistake. I had lost the only application of the Documents folder icon.
I read all the confident messages in various places about cmd-C, cmd-V etc, so I tried it on the DocumentsFolderIcon.icns file. No dice. What gets copied is a single image - the largest - so that the page outline gets progressively paler as the icon gets smaller.
Then I found this posting of yours.
Not knowing who Damien was, I didn't put the file (which is an executable
setfileicon: Mach-O universal binary with 2 architectures setfileicon (for architecture ppc): Mach-O executable ppc setfileicon (for architecture i386): Mach-O executable i386
) in /bin, but left it in Downloads, then ran it from there as ./setfileicon /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/DocumentsFolderIcon.icns ~/Documents
Worked a treat. I'll try to get hold of the source so that I can compile this myself.
P.S. I suspect that folks may have problems when they try to set the icon on a folder to which they have insufficient permissions.
Hurrah. Works like a charm. Thanks.
I have run into a bit of oddness with this script - after a file has the icon set - if I try to set it again - or change it to a different icon - i get an error message Cannot create resource fork at (filename) : error #-48