TL;DR I need to find the name of the process being run by any app I have open. I need to input this into ps h -C to, at any time, see if the app is running.
I have a bash script written that opens an app, but only if it's not already running. It is extremely simple, so here is the whole thing.
~/.config/runifnotrunning.sh
if (( $(ps h -C $2 | wc -l) == 0 )); then
exec $1
fi
The code below is the bit of code that I am struggling with.
$(ps h -C $2 | wc -l)
It returns 0 when the process isn't running and something else when the process is running.
For an app like Brave, I can run
./runifnotrunning.sh brave brave
because the name of the process and the command to run brave are the same. The issue I'm having is when I don't know the name of the process. IntelliJ IDEA (installed with JetBrains Toolbox), for example, is run with
exec "~/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/201.7846.76/bin/idea.sh" %f
But what do I put inside $(ps h -C $2 | wc -l)?
I would like to know how I can find the name of the process to put in that code for any of my apps.