Change icon of selected folder? (or file)

Is it possible to change the icon of the folder (or file) currently selected in Finder?

Ideally I’d select a folder, run the script and it would change the icon of the folder to that of an icon from a specified location (e.g. ~/Documents/Icons/exampleicon.icns), or if using an .icns file isn’t possible maybe it could copy the icon from another file, folder or application? (e.g. ~/Documents/Icons/foldericon) in the same way you can Get Info on a file, copy the icon, Get Info on another file and paste the icon to it.

Is something like this possible? Any help would be greatly appreciated.

See my command line tool SetFileIcon. There’s an example applescript to show you how to use it.

That’s brilliant. Thank you so much!

Do you know the AppleScript to get the currently selected Finder item and then run SetFileIcon to apply the icon to it that’s specified in the script?

Glad you like it. Just use this in place of theFile line…

tell application "Finder"
	set theSelection to selection -- This is a list of selected items, even if only 1 item is selected.
	set theFile to (item 1 of theSelection) as text -- Get the first item in the list. We make it text so we can convert it to a posix path for SetFileIcon.
end tell

Thanks so much (again). This is exactly what I wanted :smiley:

Sorry, one last thing if you don’t mind :slight_smile:

What would be the AppleScript to remove the custom icon from the file/folder currently selected in Finder?