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
? – jippie Dec 25 '12 at 22:15exit 1
– jippie Dec 25 '12 at 22:42exit 1
. Same result. How did you launch the script? Did you use./intellilaunch.sh xclock
or something else? – Glutanimate Dec 25 '12 at 22:53