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
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 http://search.lists.apple.com/applescript-studio
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
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)
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.
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 *.