Script that change a icon on a folde, works not in OSX.


I have this small script that change a icon on a folder, this script work in O.S 9.0 but not in OSX.

What do I need to do so I can use this script in OSX?

Any help and examples would be great.
Thanks in advance


set err to “”
tell application “Finder”
choose file with prompt “Choose the file whose icon you want to copy”
set newIcon to icon of the result
choose folder with prompt “Choose folder whose icon you want to change”
set folderName to the result as alias
set the icon of folderName to newIcon
on error errMsg
set err to errMsg
end try
end tell
return err

Since OS X, the Finder can’t manipulate icons (I don’t know if this still applies to Panther). You can try the command “transfer icon from” from Extra Suites, but I don’t know if this will work from-file-to-folder.

Also, I remember a post at Apple’s AppleScript Studio list where someone posted a method (probably a little of obj-c) to get and set icons. However, I can’t remember the location of such post in my archives, and perhaps it only worked to snag icon for files and apply them to image views… Hmmm… I just can’t remember. If you wish, take a look to their archives at

Thanks for the advice jj.

Sadly I don’t know much about obj-c.
But I did a search in the, just to see if I could find something useful.

I did also try the Extra Suites. The script ‘change icon’ inside Input Commands:

This only a part of the script:

tell application “Finder”
select item “images” of desktop – select an item
end tell

tell application “Extra Suites”
type key “i” with command – open get info
type key “c” with command – copy icon
end tell

This open the info, but it is not able to copy the icon. Probably because the icon isn’t selected (have the blue frame).

Hmmm… Am I the only one that wish/need to get and set icons?

I really hope someone can help me.


You are not the only I promise, although I don’t have answers either. Anyone?

Here is a method, but you need a couple of tools (be careful with your tests).

STEP 1. Copy the file/folder to the clipboard
Eg, manually, select any item in your desktop and type apple+c.
This will put in the clipboard lots of useful info, such as... Its icon!
You can do the same using System Events or a similar technique. Eg:

tell application "Finder" to select folder "whatever" of desktop

tell application "System Events"
	set frontmost of process "Finder" to true
	keystroke "c" using command down
end tell

delay 1 --> while the copy is done


--> extract icon data from the clipboard
set iconStuff to «class icns» of (the clipboard as record)

--> define target folder and icon file
set theFolder to "/users/joe/desktop/test folder"
set iconFile to theFolder & "/icon

STEP 2. Install "Satimage.osax" (if needed)
and use it to store the data in the related file
put resource iconStuff to (iconFile as POSIX file) type "icns" index -16455 with name ""

STEP 3. Install Developer Tools (if needed) and use SetFile
to activate the "has custom icon" flag of the target folder and,
if needed, make the icon file invisible
do shell script "/Developer/Tools/SetFile -a C " & quoted form of theFolder
do shell script "/Developer/Tools/SetFile -a V " & quoted form of iconFile

--> update stuff to show changes
tell application "Finder" 
	update (theFolder as posix file)
	update (iconFile as posix file)
end tell

Is it possible to use some built-in command-line tools to accomplish this step (without the help of Satimage.osax)? Like Rez/DeRez etc.? I have zero experience with these tools so it’d be helpful if you could give a hint or two. Thank you.

It should be possible, but I don’t know how and didn’t find a bit of useful information… :cry:

Finally have time to come back to this one: if you already have a customized icon for a folder, the file is already in that folder with a name Icon^M (^M is a newline char). You can just use /Developers/Tool/CpMac to copy that file with resource fork to a folder you want to customize, say the folder is foo:

/Developers/Tool/CpMac Icon* /someplace/foo

Note I avoid the problem of typing ^M in Terminal by just using a *.

And then you do this

/Developers/Tool/SetFile -a C /someplace/foo

and there you go - no AppleScript needed. :wink: