Advertisement
banovski

Breaks notification

Sep 17th, 2022
942
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.31 KB | None | 1 0
  1. #!/bin/bash
  2.  
  3. # The script reminds to take breaks. It checks the uptime and the
  4. # current time and depending on their values opens a notification
  5. # window saying either to turn off the computer or to exercise;
  6. # alternatively it just beeps. The script is started as a cron job
  7. # every half an hour, so an appropriate entry should be created. The
  8. # script uses espeak, yad, uptime, date, sox and a GTK icon set; so
  9. # they should be installed on the machine.
  10.  
  11. function announcement()
  12. {
  13.     espeak -v english "$1" &
  14.     yad --notification --image="$2"
  15.     yad --title="Break!" --text="$3" --image="$4" --borders=8 --width=256 --button='Dismiss!gtk-cancel'
  16.     exit 0    
  17. }
  18.  
  19. hours_of_uptime=$(uptime -p | cut -d ' ' -f 2)
  20. minutes_of_uptime=$(uptime -p | cut -d ' ' -f 4)
  21.  
  22. if (("$hours_of_uptime" % 3 == 0)) && (("$minutes_of_uptime" < 30)); then
  23.     announcement "Relax!" "emblem-colors-red" "Turn off the computer!" "exit"
  24. fi
  25.  
  26. current_hour=$(date +%H)
  27. hours_no_leading_zeros=${current_hour#0}
  28. current_minute=$(date +%M)
  29. minutes_no_leading_zeros=${current_minute#0}
  30. total_minutes=$((minutes_no_leading_zeros + hours_no_leading_zeros * 60))
  31.  
  32. if ((total_minutes % 90 == 0)); then
  33.     announcement "Exercise!" "emblem-colors-yellow" "Exercise!" "applications-sports"
  34. fi
  35.  
  36. play -n synth 0.05 sine 220 vol -20dB
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement