Copy the icon from one item to another

This script uses gui-scripting to automate the copying of one Finder item's icon to another.

 

Usage...

Modify the first two lines to point to two files you'd like to use. The 'sourceIcon' variable refers to the item whose icon will be copied to the target item. The 'targetIcon' variable declares the item whose icon will be changed. To make it more useful, you'd probably want to use 'choose file' or 'choose folder' to gather the file alias' rather than hard-coding them.

Code...

set sourceIcon to alias "Macintosh HD:Users:you:Desktop:Some Item 1"
set targetIcon to alias "Macintosh HD:Users:you:Desktop:Some Item 2"

tell application "Finder"
	activate
	set tmpIconWindow to name of (open information window of sourceIcon)
end tell

tell application "System Events"
	tell application process "Finder"
		tell window tmpIconWindow
			keystroke tab
			keystroke "c" using command down
		end tell
	end tell
end tell

tell application "Finder"
	close window tmpIconWindow
	set targetWindow to name of (open information window of targetIcon)
end tell

tell application "System Events"
	tell application process "Finder"
		tell window targetWindow
			keystroke tab
			keystroke "v" using command down
		end tell
	end tell
end tell

tell application "Finder" to close window targetWindow

Notes...

Gui-scripting carries with it some inherent risks and error possibilities. I wouldn't recommend working this code into a publicly available app, but it works all right for simple desktop use.

 

 

Hosted by www.Geocities.ws

1