How To Add Different Icons To Application Instances On Macosx
I run multiple Alacritty instances for my development workflow. Each instance uses tmux to manage multiple windows - one per project. I have one Alacritty instance that runs GitUI in full screen mode and the other instance runs the continuous compilation of each project in its own window. Oh, and they also run on separate monitors.
Monitor Configuration
I have one horizontal 32” monitor which is my primary screen and a 27” monitor turned vertical for my secondary screen.
Primary Monitor
The main monitor runs Alacritty with GitUI.
Secondary Monitor
The secondary monitor runs another Alacritty instance with continuous compilation with the respective project’s compiler. If the project doesn’t have a compiler, the window opens to the project location from which I can run various commands.
The Issue
So what’s the problem that requires different application icons per instance?
When I run two instances of Alacritty, this is what my Application Switcher (CMD
+ TAB
) looks like:
It becomes very hard to distinguish between the Gitgui
Alacritty and the Project
Alacritty instances. More often than not I pick the wrong one and have to try and choose a second time. It’s a little annoying.
I can use Misson Control to display all the windows and choose from there.
The reason I don’t want to do this is because I’ve got an old MacBook Pro and zooming into Misson Control is slow. The whole process of:
- Go to Mission Control
- Choose your Alacritty Window
- Switch to that Window
takes about 2 seconds. That’s way too long to maintain any kind of flow state when coding.
The Solution
- Create a copy of the application folder
For example to create an Alacritty instance for Whatever
s I can create a copy with:
cp -r /Applications/Alacritty.app /Applications/Alacritty-Whatever.app
- Open
Finder
and browse to the freshly copied application folder (/Applications/Alacritty-Whatever.app
in the above example)
- Open the information panel with
CMD
+I
:
- Find a new image (use Google Images, macosicons etc)
- Drag the new image to the icon placeholder
- Launch Copied app through Spotlight or Alfred
- Check the Application Switcher
Final Result
I used the above steps to create custom icons for Alacritty for both my projects and GitUI instances.
The key is to launch the Alacritty-Projects application for projects and Alacritty-GitUI application for git-related work.
Downsides
This is the simplest way to give different application instances different icons that I have found. You have to essentially create a new application (by copying an existing one) just to change an icon for a different instance. You need one copy per instance you want to customise the icon for. This seems a little crazy.
If you know of an easier/better way to do this please drop me comment.
Unfortunately any time you update the original application (Alacritty in this instance) you need to recreate your copies and do the whole updating icon dance.
Scripting
This whole process is pretty easy to script, providing you can create an icns file for the image you require or already have an alternate icns file. But it is not as reliable as the steps outlined above, as sometimes icon caching issues makes it hard to refresh the new icons. See below for more details
Generating an icns File
There’s a program called mkicns that lets you convert images from various formats like jpg, png etc to icns files that are used for your application icons.
You can install it through Homebrew:
brew install makeicns
You can generate an icns file for a given image with:
makeicns -in your-image_file -out your.icns
There are a bunch more options for makeicn, so make sure to check the --help
option for any customizations you want to make.
Icon Refresh Issues
Now that we have our own icns file, we can do the following:
- Create a copy of the application folder as above
- Copy across the custom icns file into the
Content/Resources
folder and replace the existing icns file you want to replace.
For example for Alacritty, the main ics file is Content/Resources/alacritty.icns
, so you’d do:
cp your.icns /Applications/Alacritty-Whatever.app/Content/Resources/alacritty.icns
Now if you try to launch your custom application with your new shiny icon you will notice that it has not been updated.
In order to do that you need to help macos understand that the application has changed and you may need to some or all of the steps below:
- touch the application folder
touch /Applications/Alacritty-Whatever.app
If that doesn’t work you may also need to do the following:
- Kill all the things
sudo killall Finder
sudo killall Dock
These steps are from Changing Mac OS X Application Icons Programmatically.
A full working script:
#!/bin/bash
cp -r /Applications/Alacritty.app /Applications/Alacritty-Whatever.app
cp whatever.icns /Applications/Alacritty-Whatever.app/Content/Resources/alacritty.icns
touch /Applications/Alacritty-Whatever.app
sudo killall Finder && sudo killall Dock
And hopefully that should be it. But sometimes it isn’t.
If that doesn’t work you may need more drastic workarounds.
And at end of those drastic workarounds you might revert to just using the list of steps at the top of this article.
A big thank you to Apple for making all this so damn hard.