Skip to content

Instantly share code, notes, and snippets.

@akshaykarnawat
Last active October 4, 2019 04:12
Show Gist options
  • Save akshaykarnawat/e01d040fb9283f1f8e4063e8220a283c to your computer and use it in GitHub Desktop.
Save akshaykarnawat/e01d040fb9283f1f8e4063e8220a283c to your computer and use it in GitHub Desktop.
Eye Care 20-20-20 rule
from os import popen, system
from time import sleep
# Note: this requires brightness package to be installed from homebrew
# https://brew.sh
# brew update; brew upgrade; brew install brightness
# #future -- rewite as shell script..no need for py
CURRENT_BRIGHTNESS = 1
def _set_current_brightness():
CURRENT_BRIGHTNESS = popen("brightness -l | grep brightness | awk -F' ' '{print $4}'").read().replace('\n', '')
def full_dim():
system('brightness 0')
def un_dim():
system('brightness %s' % CURRENT_BRIGHTNESS)
def say(msg):
system('say %s' % msg)
def timer_count(seconds):
timer = 0
while(timer <= seconds):
say(timer)
timer += 1
def main():
while (True):
# go to seep for 20 min
say('Setting the timer for 20 min')
sleep(20*60)
# begin the counter for 20 seconds
_set_current_brightness()
full_dim()
say('Look away for 20 seconds at an object that is 20 feet away')
timer_count(20)
un_dim()
if __name__ == "__main__":
say('Running eyecare services')
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment