SHARE
TWEET

Untitled

a guest Jan 11th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. #suspends the computer when mpd gets paused
  3. if ! command -v > /dev/null mpc
  4. then
  5.     echo "error: this needs mpc to be installed"
  6.     exit 1
  7. fi
  8. uid=$(id -u)
  9. pidfile="/var/run/user/$uid/mpd-suspend-on-pause.pid"
  10. if [[ "$1" == "-k" ]] # kill
  11. then
  12.     if [[ -f $pidfile ]]
  13.     then
  14.         (kill "$(cat $pidfile)" 2> /dev/null) || (>&2 echo "not running";exit 1)
  15.     fi
  16. elif [[ "$1" == "-s" ]] # status
  17. then
  18.     if [[ -f $pidfile ]] && ps $(cat $pidfile) > /dev/null;
  19.     then
  20.         echo "running"
  21.     else
  22.         echo "not running"
  23.     fi
  24. else
  25.     if [[ -f $pidfile ]] && ps $(cat $pidfile) > /dev/null;
  26.     then
  27.         (>&2 echo "already running")
  28.         exit 1
  29.     else
  30.         while (true)
  31.         do
  32.             mpc idle > /dev/null
  33.             if [[ ! $(mpc status | grep playing) ]]
  34.             then
  35.                 systemctl suspend -i
  36.                 break
  37.             fi
  38.         done &
  39.         echo "$!" > $pidfile
  40.     fi
  41. fi
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top