I compiled a short bash one-liner to focus a running application or launch it if it isn't running:
#!/bin/bash
#intellilaunch.sh
wmctrl -a $1 || $1 & disown
exit 1
The command exits perfectly fine when run directly from the command line:
:~$ wmctrl -a firefox || firefox & disown
[1] 32505
A quick check with the system monitor shows that only firefox is running.
However, when I launch firefox via the script (./intellilaunch.sh firefox) it spawns a persisting new process called intellilaunch.sh firefox, which only exits after closing firefox.
What am I doing wrong?
Edit:
I modified my script according to michas' suggestion:
#!/bin/bash
program=$(basename $1)
if ! wmctrl -a "$program"; then
"$1"&
fi
Not a one-liner anymore but it works perfectly fine now!
xclock?exit 1exit 1. Same result. How did you launch the script? Did you use./intellilaunch.sh xclockor something else?