Copying custom icons between folders..

I want to copy a custom icon from one to another folder and made this script.
However, Finder claims that file1 (invisable icon file in the first folder) cannot be found.

What am I doing wrong…?

tell application “Finder”
set aFold to choose folder “Select folder to copy icon”
set bFold to choose folder “Select folder to transfer to”
set aFold to aFold as string
set file1 to (aFold as string) & “.DS_Store”
set file2 to (aFold as string) & “Icon”
copy alias file1 to bFold
copy alias file2 to bFold
end tell


Eelco Houwink


Mmm… I’m not sure, but I think that, effectively, file “Icon” doesn’t exists, because it has appended an ascii char 13. Try using

set file2 to (aFold as string) & "Icon
"

and tell us…

Eelco,

After posting this I re-read your post and have further questions. The script below will copy an icon, from one selected folder, to another. Your post mentions something about invisible file “icon” and I see you are concatenating a file name to the end of the folder. Does that mean you want to copy the icon of an invisible file? -Or are you just trying to copy the icon from one folder to another? The script below will. --Good luck

Try this, works for me on OS 9.2.1 / AS v 1.6

tell application "Finder"
	activate
	set aFold to choose folder with prompt "Select folder to copy icon"
	set bFold to choose folder with prompt "Select folder to transfer to"
	set aFold to aFold as string
	select alias bFold
	set the icon of selection to the icon of folder aFold
end tell

Best,

I was trying to work out how to swap icons on one of my scripts and this helped me out, too.

You’re trying to copy the invisible icon file from one folder to the other - which can’t be done explicitly. As Mytzlscript suggests, it’s simpler to use the folders’ ‘icon’ property in the Finder. (By the way, you need ‘with prompt’ before the text in the ‘choose folder’ statements.)

tell application "Finder"
  set aFold to choose folder with prompt "Select folder to copy icon"
  set bFold to choose folder with prompt "Select folder to transfer to"
  set bFold's icon to aFold's icon
end tell

As an interesting aside: I’ve just been fooling around with this script for fun, turning it into a (not recommended) one-liner. To my surprise, the from ‘choose folder’ is still executed before the to ‘choose folder’, even though it comes after it in the line. I suppose that’s obvious in retrospect; I’d just never thought about it before. :slight_smile:

tell application "Finder" to set (choose folder with prompt "Select folder to transfer to")'s icon to (choose folder with prompt "Select folder to copy icon")'s icon

None of these have been working for me. I get error such as…“Can’t get icon of folder /1”
The folder path is different, but i just don’t feel like typing it out. I’m trying to hard code it, instead of using a selector. Any one have any ideas?

They don’t work for me in OS X 10.2.8 either, though they work fine in classic Finders. If you’re using OS X, I don’t think ‘icon’ scripting has been reintroduced yet. :frowning:

Yeah, I’m running OSX 10.3.5 and i get all these weird errors, guess i’ll just have to watch for updates :frowning: