This shell script should handle the starting and stopping of any program:
if [ "$?" -eq "0" ]; then
echo "at least one instance of "$BASECMD" found, killing all instances"
echo "no running instances of "$BASECMD" found, starting one"
let's say you saved it under
~/mystarter, you can run any command with it using
~/mystarter <name>, eg in your case, bind Meta+R to:
and make sure the script is executable:
chmod u+x ~/mystarter. Also it's probably best to put it somewhere in your
PATH, so you don't have to type it's full location every time.
As for the fact that
gnome-run doesn't show up in
ps -A, make sure that gnome run itself isn't a script that launches the actual process. Check if there is a difference between
ps -A | wc -l before and after launching it (this counts all running processes).
Since you've accepted the answer, I thought I'd add support for running commands that have commandline arguments, so that this might become a place of reference. Run a command like so:
./mystarter 'cmd args'
./mystarter 'ncmpcpp -c ~/.ncmpcpp'
The command just looks up
ncmpcpp to see if it's running already, but executes the full command (with arguments) when
ncmpcpp wasn't running.