From c91cf1d41af565dcab6a628696d7571339c5c4c2 Mon Sep 17 00:00:00 2001 From: Nikolay Puzanov Date: Fri, 23 May 2014 15:34:25 +0400 Subject: [PATCH] Add script for stop timer when screen is off --- timer-auto-stop.sh | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 timer-auto-stop.sh diff --git a/timer-auto-stop.sh b/timer-auto-stop.sh new file mode 100755 index 0000000..4cc5392 --- /dev/null +++ b/timer-auto-stop.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +timer_is_start() +{ + if [ "$(timer)" = "NO TASKS" ]; then + echo "off" + else + echo "on" + fi +} + +screen_status() +{ + local xset_status=$(xset q | grep "Monitor is") + + if [ "$xset_status" = " Monitor is On" ]; then + echo "on" + elif [ "$xset_status" = " Monitor is Off" ]; then + echo "off" + else + echo "unknown" + fi +} + +timer_on=$(timer_is_start) +scr_status=$(screen_status) + +while true +do + scr=$(screen_status) + + if [ $scr != $scr_status ]; then + case $scr in + on) + if [ $timer_on = "on" ]; then + timer start + fi + ;; + off) + timer_on=$(timer_is_start) + if [ $timer_on = "on" ]; then + timer stop + fi + ;; + esac + fi + + scr_status=$scr + + sleep 5 +done