Set a custom dock icon for an application instance via Terminal

Solution 1:

I don't have a complete solution for you, but from looking through the man pages, I think I kinda see how one might be crafted.

  • open(1) provides the --args option for passing arguments on to the invoked application.

  • emacs(1) will read values from an .Xresources file. One of the values it reads is emacs.iconName.

  • X allows you to select Xresources for a specific app by setting $XENVIRONMENT to contain the path of a file containing Xresource values. Also, X programs are supposed to support the -name and -title options for setting (I think) the name of an Xresource file to be loaded and/or the title of the application instance.

So I haven't tested this, but you might be able to do something like:

open -n -a Emacs.app --args "-name <resource-file-path> -title school"

Then, in the resource file, a line that says

emacs.iconName:<path-to-school-icon-file>

In another resource file, you'd have iconName set to a work icon, etc.

If you try this, I'd be interested in knowing how it works out.