(*
This applescript allows bulk setting custom icons for apps (or folders)
It cannot set icons for system apps like Safari
or apps you do not own such as those installed from the App store
Tested working on Sonoma 14.5
USAGE: Create a text file called replicons.cfg in your Documents folder
following this format
<app1-posix-full-path>,<icon1-posix-full-path>
<app2-posix-full-path>,<icon2-posix-full-path>
...
Icon may be of type .icns or an image type such as .png
Example:
/Applications/Google Chrome.app,/Volumes/T7/icons/chrome dark.icns
/Applications/foobar2000.app,/Volumes/T7/Downloads/foobar2000.icns
/Applications/Spotify.app,/Users/me/Documents/icons/Spotify.png
To revert an icon to the default, leave the icon field empty (note the comma)
/Applications/Spotify.app,
Do not leave blank lines or leading / trailing white spaces.
Stackexchange discussion
https://apple.stackexchange.com/questions/473597/change-apps-icon-by-script
*)
use framework "Foundation"
use scripting additions
set configFile to (path to home folder as text) & "Documents:replicons.cfg"
-- Function to set the icon for a given application
on setAppIcon(appPath, iconPath)
try
-- the magic happens here
if iconPath is "" then
set image to missing value
else
set image to current application's NSImage's alloc()'s initByReferencingFile:iconPath
end if
set success to current application's NSWorkspace's sharedWorkspace's setIcon:image forFile:appPath options:0
return success
on error errStr number errorNumber
display dialog errStr
return false
end try
end setAppIcon
-- Parse a line from the config file
on parseLine(aLine)
set AppleScript's text item delimiters to ","
set parsedList to text items of aLine
set AppleScript's text item delimiters to ""
return parsedList
end parseLine
-- Read the appIconPairs from an external text file
set appIconPairs to {}
try
set fileContents to read (configFile as alias)
set fileLines to paragraphs of fileContents
repeat with aLine in fileLines
if aLine is not "" then
set {appPath, iconPath} to my parseLine(aLine)
copy {appPath, iconPath} to end of appIconPairs
end if
end repeat
on error errStr number errorNumber
display dialog errStr
return
end try
set successCount to 0
repeat with appIconPair in appIconPairs
set {appPath, iconPath} to appIconPair
if setAppIcon(appPath, iconPath) then
set successCount to successCount + 1
end if
end repeat
if successCount > 0 then
-- Restart the Dock to refresh the icons
do shell script "killall Dock"
display dialog "Successfully replaced " & (successCount as string) & " icons."
else
display dialog "No change made."
end if