I am trying to write a script file and invoke it using XFCE global shortcut. The script should continue the Audacity application if it is in the stopped state and stop it (pause recording) if it is in the run state. This will be useful when I have defined the same keyboard shortcut for VLC's playback/pause. This way, I can do playback/pause (in VLC) and record/pause (in Audacity) at the same time using the same keyboard shortcut. Getting some ideas from this post I have written the following script and added it to XFCE's custom keyboard settings. But it does not work.   #!/bin/bash if pgrep -f audacity ;    then       pkill -stop audacity && notify-send Recording stopped    else       pkill -cont audacity
How to make a script toggle between two commands when it is executed?
scripting;keyboard shortcuts;xfce;vlc;audacity
To be able to know whether to send the STOP or the CONT signal to the process, you will have to figure out its current state first.If it's stopped, you should send CONT.If it's not stopped, you should send STOP.The state of a running process may be found with ps. If a process is stopped, then it its state, as reported by ps -ostate= will contain the letter T (the equal sign will stop ps from outputting a header).#!/bin/bashcommand=audacitypids=$( pgrep $command )if [[ -z $pids ]]; then    printf '%s is not running\n' $command >&2    exit 1fifor pid in $pids; do    state=$( ps -ostate= -p $pid )    stopped=0    case $state in        *T*)    stopped=1 ;;    esac    if (( stopped )); then        kill -s CONT $pid        printf '%s (%d) has been unpaused\n' $command $pid    else        kill -s STOP $pid        printf '%s (%d) has been paused\n' $command $pid    fidoneThere is a theoretical race-condition in the script whereby the command may have quit between the call to pgrep and the call to kill.  All that will happen in that case is that kill will complain about no such process.