Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

folder icon command line

Hi,

setting a custom item for a folder is easy with the copy/paste method. But I would like to script it.

As far as I have seen, if a custom icon is set for a folder, inside that folder an Icon file is created and the data (the icon itself) is saved in the "resource fork" (0KB for the file in the terminal, but on a smb-server, the file is split into 2 files and the ._Icon file has some 100KB).

But just copying that Icon file over (from a folder, where it is set to the folder, where I want it to show up) with cp or ditto -rsrc doesn't help. The Icon for the folder doesn't change.

Do you know how to change the folder icon in a script (be it bash or Apple script)?
What would be the commands to set a custom icon for a folder?

thanks, kind regards, Herlind

Mac Book Pro, Mac OS X (10.5.7)

Posted on Jun 25, 2009 6:28 AM

Reply
2 replies

Jun 25, 2009 9:07 AM in response to Herlind

Hello Herlind,

I think you need not only to copy the 'Icon\r' file to the destination folder but also to set the custom icon flag of destination folder.
Try something like this. It uses SetFile command of Developer Tools.

--SCRIPT (not tested)
set src to POSIX path of (choose folder with prompt "Choose source folder.")
set dst to POSIX path of (choose folder with prompt "Choose target folder.")
copyCustomIcon(src, dst)

on copyCustomIcon(src, dst)
(*
string src, dst : POSIX path of source and destination folders
*)
set srcicon_ to quoted form of (src & "Icon" & return)
set dst_ to quoted form of dst

set sh1 to "ditto --rsrc --extattr " & srcicon_ & " " & dst_ -- copy icon file to dst
set sh2 to "/Developer/Tools/SetFile -a C " & dst_ -- set custom icon flag of dst
do shell script (sh1 & " && " & sh2)
end copyCustomIcon
--END OF SCRIPT

cf.
http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/SetFile. 1.html

Hope this may help,
H

Jun 25, 2009 11:20 AM in response to Herlind

Here is an alternative solution which just uses GUI scripting. The following script will set the icon of folder "Folder 2" to the icon of folder "Folder 1" (both folders on the desktop) :

tell application "Finder"
activate
open information window of folder "Folder 1" of desktop
tell application "System Events" to tell application process "Finder"
set value of attribute "AXFocused" of button -1 of scroll area 1 of window 1 to true
keystroke "cw" using command down -- copy the icon, then close the information window
end tell
open information window of folder "Folder 2" of desktop
tell application "System Events" to tell application process "Finder"
set value of attribute "AXFocused" of button -1 of scroll area 1 of window 1 to true
keystroke "vw" using command down -- paste the icon, then close the information window
end tell
end tell

Message was edited by: Pierre L.

folder icon command line

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.