Hi,
@macsparky demonstrated in his Paperless Field Guide a method to change the icon of his Action folders. I thought would share a couple of AppleScript routines I use to automate this process.
Both examples use a dedicated folder where I store my icns files. I would recommend the Image2Icon app to create these files which is available via the SetApp subscription.
The first example will prompt you for the icon to use then for the folder to apply it to;
use framework "Foundation"
use framework "AppKit"
use scripting additions
set iconFolder to (path to home folder as text) & "Automation:Folders:Icons" -- Location of your icns files
set icon to choose file with prompt "Please choose an icon" default location POSIX path of iconFolder of type {"Public.image"}
set Destination to choose folder with prompt "Please choose the Folder to change "
set destPath to POSIX path of Destination
set sourcePath to POSIX path of icon
set imageData to (current application's NSImage's alloc()'s initWithContentsOfFile:sourcePath)
(current application's NSWorkspace's sharedWorkspace()'s setIcon:imageData forFile:destPath options:2)
This example will apply the icon chosen by a prompt to the selected folder;
use framework "Foundation"
use framework "AppKit"
use scripting additions
set iconFolder to (path to home folder as text) & "Automation:Folders:Icons" -- Location of your icns files
set icon to choose file with prompt "Please choose an icon" default location POSIX path of iconFolder of type {"Public.image"}
try
tell application "Finder"
set destination to the selection as alias
end tell
on error
display dialog "An error has occurred, did you select a single folder?"
end try
set destPath to POSIX path of destination
set sourcePath to POSIX path of icon
set imageData to (current application's NSImage's alloc()'s initWithContentsOfFile:sourcePath)
(current application's NSWorkspace's sharedWorkspace()'s setIcon:imageData forFile:destPath options:2)
Cheers
Iain