May 21, 2020.
This article will go through two different ways on how one could programmatically change app icons on macOS.
There have been multiple ways one could manually go about changing app icons for installed apps on macOS, which include replacing dragging an icon file on the application icon in the applications inspector window or using a 3rd party app like LiteIcon to do so. This can potentially be annoying as icons change back to defaults if you update the app or simply because it is a pretty tedious process.
This process can potentially be automated by using a script to replace the icons.
By using the ‘fileicon’ utility by Michael Klement[1] we can pretty much change icons for any file or folder on macOS. Using the following command
or remove the set icon using
fileicon can be installed using brew, make sure you have the command line tools installed.
Here’s an example script, written using the fileicon utility
1
2
3
4
5
6
#!/bin/bash
icon_path=$1
app_path="/Applications/$2.app"
fileicon set $app_path "$1"
saving the above as replace.sh
and calling
would change the Spotify’s app icon.
fileicon is capable of assigning any image format macOS is capable of reading to most files and folders, I would recommend using fileicon for most scripting projects.
I recommend going with the previously mentioned method unless you know what you’re doing.
Applications on macOS function like folders, you can right-click on a folder and select ‘show package contents’ to browse the contents of an app.
In the contents directory of an application, we should find a file called ‘Info.plist’, inside the mentioned plist file we’re looking for three entries
The icon files specified in the Contents/Resources directory. It’s relatively easy to write code to replace the icons.
After replacing the icons specified by the plist, we’ll need to refresh the icon cache. There are numerous ways to execute this as discussed in a Github Gist by Fabio Fernandesthread[3] with a discussion about their drawbacks.
I’ve found the easiest way to achieve this is by simply touching the application, and restarting Finder and Dock.
1
2
touch /Applications/[name].app
killall Finder && killall Dock
[1] fileicon. Michael Klement, Github.
[2] Core Foundation Keys. Apple Documentation.
[3] “Clear Mac OS X’s icon cache”. Fabio Fernandes. Github Gist.