Hello,
Ciao,
Hola,
Bonjour,
Hey,
I am Manik

Programmatically changing icons on macOS .

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.

The Process

The easier way

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

fileicon set [path_to_file] [path_to_icon]

or remove the set icon using

fileicon remove [path_to_file] [path_to_icon]

fileicon can be installed using brew, make sure you have the command line tools installed.

brew install fileicon

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

./replace.sh desktop/iconreplacement.icns Spotify

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.

The harder way

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

  • CFBundleIconFile: Icon that shows up in dock and Launchpad[2].
  • CFBundleIconFileDark: Icon that shows up in the dock and Launchpad when dark mode is enabled[2].
  • CFBundleTypeIconFile: Icon that shows up when on a file that can be showed up in the said application[2]. As a caution, often applications can support opening a lot of different kinds of formats, which leads to dealing with a lot of different icons or just convoluted code.

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

References

[1] fileicon. Michael Klement, Github.

[2] Core Foundation Keys. Apple Documentation.

[3] “Clear Mac OS X’s icon cache”. Fabio Fernandes. Github Gist.