Set custom icon flag in applescript?

Im in the midst of making a script that will change the contents of a file, give it a new extension, and give it a custom icon. After much testing, I’ve come to the conclusion that the reason the custom icon (at index -16455, type “icns”) doesn’t show up is because of some finder flag associated with it. My conclusion is based on the fact that finder flags take up no file space. Try doing an md5 checksum on a file with and without an “invisible” finder flag, which otherwise is the same file. The checksum is identical. Similarly, the checksum showed a file with a displaying and non-displaying custom icon to also be identical (at least, in terms of its data & resource fork contents). I have tried “tell application “Finder” to update alias path:to:my:file” and that didn’t work.

I’ve found a command-line utility that can edit finder flags (looks pretty cool; check it out here), but I haven’t found any applescript coercions or shell script commands that do this.

Note - I do not have, and do not intend to install, XCode. I just can’t afford the hard disk space.

Anyone familiar with this issue? :confused:

Hi Alex,

Do the files you want to put custom icons on have any other resources than the -16455 icns? I don’t think it realy matters though as you can copy the rest of the resources. What I did was keep a blank file with has custom icon flag set. I put that file named “rsrc” in a folder named “CustomIcon” on my desktop. Once you have this setup you can copy the custom icon of another file to a duplicate of the blank file, using Satimage osax, with something like this:


set f1 to choose file with prompt "Choose a file with custom icon:"
set icns to load resource -16455 type "icns" from f1
tell application "Finder"
	set f2 to (duplicate file "rsrc" of folder "CustomIcon" of desktop to desktop) as alias
end tell
put resource icns to f2 type "icns" index -16455

Rem: that both the chosen file f1 and the template file “rsrc” has to have a custom icon. Afterwards, you need to update the Finder.

Another way is to ui script the info window of a file, but I rather use the template method above.

An easy way to get a blank file is with unix ‘touch’

do shell script “touch ~/Desktop/Somef/rsrc”

Then you can write the data over to this file.

gl,