Automatic notifications for taking a break
Automate a notification to take a break
Working with computers all day is a recipe for eye strain, often leading to tired eyes by the night. The 20-20-20 rule is a guideline meant to reduce eye strain. According to the rule, one should look at something 20f away for 20s every 20 minutes. I’ve tried to follow it by memory, but mostly failed. So lets automate it! I thought of finding some app to remind me, but its more fun to do it with built-in OS features :)
Apply allows us to use osascript
to create a notification. This can be a silent notification (display notification
) or an “in your face” alert (display alert
). I chose the in your face alert because I don’t want to miss it, lets see if i regret it during my first presentation when the alert goes off.
The one liner for the alert,
1 | osascript -e 'display alert "20-20-20 Rule" message "Take a 20s break!"' |
However, I want to also receive an audio cue. You can use afplay
on mac to call a system sound. Putting the two together, gives you this script:
1 | #!/bin/zsh |
Now we have to wrap it inside a launch agent, this has to be saved in ~/Library/LaunchAgents/eye-strain-reminder.plist
with the following content:
1 | <?xml version="1.0" encoding="UTF-8"?> |
Don’t forget to update the path to the absolute path of your script!
Now you need to load and start the agent:
1 | launchctl load ~/Library/LaunchAgents/eye-strain-reminder.plist |
You can always stop
and unload
the above plist
file if you want to get rid of the job.