Tuesday, 31 May 2016

Vison 20-20-20 : A bash Script

 20-20-20 Rule


Anyone who spends more than 3 hours before a computer screen in at the risk of suffering from computer vision syndrome.  Currently an estimated 70 million computer professionals are at the risk of suffering from computer vision syndrome
A programmer spends hours before the computer. To avoid damage to eyes and prevent computer vision syndrome , the 20-20-20 rule is suggested by doctors.
The 20-20-20 rule is as follows:

Look at an object 20 feet away for 20 seconds every 20 minutes.

The Issue

It easier said then done. You simply don't remember when 20 minutes have passed. Thus I have taken efforts to help you with the 20-20-20 minute rule. I have created a bash script vision20 to help with this.

 

Vision20 - Options


It offers the following options:
  1. It runs as a script once,or
  2. It can be made a permanent command.

By permanent command I mean the following:

You can simply type vision20 & in your terminal and it will run in the background , bothering you every 20 minutes. This is possible by saving the script inside /usr/local/bin.

This entire task is automated by done , simply by selecting option two.

Note: The second option requires superuser / root access.


Working


It will turn of the screen ,every 20 minutes for 30 seconds.
In case, you were doing something important you simply press a key or move your mouse.

The script


#(assuming it is saved as vision20 )
# run it as follows 
# chmod u+x vision20.sh
# sudo  ./vision20.sh
#sudo permission required for making permanent command

echo "vision20 v1.0"
echo "An attempt to make programmers follow the 20-20-20 rule"
echo "A Script by Abhishek Munagekar"
echo "For more visit www.prgwonders.blogspot.in"
echo "Contact me @ [avm.abhishek@gmail.com]"

echo "Menu"
echo "1.One time run"
# run this one time only 
echo "2.Makes it a permanent command-requires sudo"
# add this permanently to terminal as a command
echo "3.Exit"
read choice

case $choice in
1)
clear
echo "One time run selected"
echo "Just move your mouse in case you need to work immediately"

while true
do
sleep 1200 # sleep for 20 minutes
xset -display :0.0 dpms force off # turn off
sleep 30 # sleep for 30 seconds while you focus on distant object
xset -display :0.0 dpms force on # turn on
done
;;

2)
echo "REQUIERS SUPERUSER PERMISSION"
echo "Making this a permanent command"
echo "Next time you can run this script by typing vision20 &( ampersand in for bg)  in terminal"
echo "Press enter to continue or Ctrl-Z to terminate"
touch /usr/local/bin/vision20  # remove this file to uninstall command
echo "# vision20 v1.0" > /usr/local/bin/vision20
echo "# script by Abhishek Munagekar" >> /usr/local/bin/vision20
echo "# contact me @ [email protected]" >> /usr/local/bin/vision20
echo "# blog:www.prgwonders.blogspot.in" >> /usr/local/bin/vision20
echo ' echo "to kill this script later if running in background use:- pkill -P \$\$" ' >> /usr/local/bin/vision20
echo ' echo "Press Ctrl-C to continue using the terminal..."' >> /usr/local/bin/vision20
echo "while true" >> /usr/local/bin/vision20
echo "do" >> /usr/local/bin/vision20
echo "sleep 1200 # sleep for 20 minutes" >> /usr/local/bin/vision20
echo "xset -display :0.0 dpms force off # turn off" >> /usr/local/bin/vision20
echo "sleep 30 # sleep for 30 seconds " >> /usr/local/bin/vision20
echo "xset -display :0.0 dpms force on # turn on" >> /usr/local/bin/vision20
echo "done" >> /usr/local/bin/vision20
echo "file created successufly in /usr/local/bin"
sudo chown root:root /usr/local/bin/vision20
sudo chmod 755 /usr/local/bin/vision20
echo "file permission changes successful"
echo "all operations complete"
;;

3)
echo "Terminating Script"
;;

*) 
echo "Invalid option"
;;

esac

echo "Thankyou"

Testing

Tested on 
OS : Ubuntu 14.04 LTS.
Desktop Environment: Unity

Contact


In case you experience any bug , or have a better way . Leave a comment, I am always looking forward to any constructive feedback to improve.

Image Links

https://pixabay.com/en/eye-eyeball-green-vision-sight-931978/



1 comment: