I'm using Ubuntu 20.04 and I'm looking for a bash script to start Quodlibet (a music application) and conky simultaneously. Edit: The idea is to use the sh script in a .desktop launcher
- Start Quodlibet
- Start conky 2 seconds later
- Close conky if Quodlibet is closed
I made some tests but I believe the following script won't work because I doesn't catch the closing of Quodlibet. Conky is still running when I close Quodlibet.
#!/bin/bash
trap "exit" INT TERM ERR
trap "kill 0" EXIT
quodlibet &
sleep 2 &&
conky &
wait
EDIT: Standalone .sh solution
Working script, thanks to @berndbausch.
#!/bin/bash
quodlibet & QUODPID=$!
sleep 3 &&
conky & CONKYPID=$!
wait $QUODPID
kill $CONKYPID
EDIT: Using a custom launcher
As explained by @xhienne in his answer, using exec=setsid /path/to/script.sh
in the .desktop file as well as his script works well.
QUODPID=$!
, then, after starting conky, store its PID as well. Wait for Quodlibet's termination withwait $QUODPID
. Then kill conky. – berndbausch Apr 21 '21 at 13:45CONKYPID=$!
puts the assignment into a subshell, so that the CONKYPID in the main program is not affected. Remove the ampersand and it should work. Same for the QUODPID, by the way. – berndbausch Apr 21 '21 at 14:26