This question is similar in spirit to How can I kill a process by its name?, but not a duplicate for the reason below.
As an example, here's how IntelliJ appears in Activity Monitor:
The name is "IntelliJ IDEA". This is also the name visible when you toggle windows. However
ps aux will show the process name as
idea because that's the name of the process being executed:
pkill -i intellij does nothing, as you have to type
pkill -i idea to actually kill the right process. But is there a way to do this without having to lookup the right process name first? I'd like to type in
kill_by_visible_name intellij and see the process terminated.
One option is to run
ps aux | grep -i intellij but this will also find processes that happen to run from a folder named "IntelliJ", not just the actual IntelliJ process. This will also fail for processes where the visible name is not the same as the name of the application folder. Another option is to lookup the PID within Activity Monitor, but this is time consuming when you already know the name of the application.