Skip to content

Instantly share code, notes, and snippets.

@zeekhuge
Created November 30, 2017 17:17
Show Gist options
  • Select an option

  • Save zeekhuge/e293ed5404e7952f93f0336fc6d417a5 to your computer and use it in GitHub Desktop.

Select an option

Save zeekhuge/e293ed5404e7952f93f0336fc6d417a5 to your computer and use it in GitHub Desktop.
A simple bash script that turns off your screen for `SECONDS_TO_CLOSE_EYE` after `MINUTES_TO_WORK` long work to force you relax your eyes.
#!/bin/bash
#
# Set this script to start on login using `StartUp Application`
#
########-- CHANGE THESE FOR DIFFERENT BEHAVIOUR --#############
MINUTES_TO_WORK=45
SECONDS_TO_CLOSE_EYE=60
###############################################################
SECONDS_TO_WORK=$(echo $MINUTES_TO_WORK*60 | bc)
REFRESH_TIMEOUT_SECONDS=2
MULTIPLE_OF_RTS=$(echo -e "$SECONDS_TO_CLOSE_EYE/$REFRESH_TIMEOUT_SECONDS" | bc)
for pid in $(pidof -x eyeProtector.sh); do
if [ $pid != $$ ]; then
echo "Process already running"
exit 1
fi
done
while [ 1 ]
do
sleep $SECONDS_TO_WORK
$(paplay /usr/share/sounds/ubuntu/stereo/message.ogg)
notify-send "Bro, close your eyes for 2 minutes"
sleep 5
I=0;
while [[ I -le $MULTIPLE_OF_RTS ]];
do
xset -display :0.0 dpms force off
I=$(echo "$I+1" | bc)
sleep $REFRESH_TIMEOUT_SECONDS
done
$(paplay /usr/share/sounds/ubuntu/stereo/message.ogg)
notify-send "Back to work"
xset -display :0.0 dpms force on
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment