lexthebrony

Sleep Music Timer

Nov 1st, 2014
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.63 KB | None | 0 0
  1. #!/bin/bash
  2. #VERSION2! Adds in a while loop which requires valid input and only
  3. #spawns processes if valid input is given.
  4. #This emulates the play/pause media button after the specified time.
  5. #This REQUIRES xdotool as well as a player/shell that supports media keys.
  6. param1=$1
  7. re='^[0-9]+$'
  8. while ! [[ $param1 =~ $re ]]
  9. do
  10.     read -p "Specify time in minutes: " param1
  11.     echo $param1
  12. done
  13. if  [[ $param1 =~ $re ]]
  14. then
  15.     (sleep $param1"m" && xdotool key XF86AudioPlay) &
  16.     echo "Pausing playback in $param1 minutes... sleep well!"
  17. fi
  18. #the parens run in subshell to suppress output as well as sleep in bg
  19. #code by Noah B. Rawr.
Advertisement
Add Comment
Please, Sign In to add comment