DO YOU keep meaning to start following the 20-20-20 rule that your eye doctor told you about? Here's a tutorial for setting up your Mac to remind you to take that break every twenty minutes. It consists of the following:
- A simple shell script that shows the notification
- A Mac OS launchd agent that sets up the recurring reminder
- Commands to initialize the agent.
First, the shell script:
# ~/scripts/twenty.sh osascript -e 'display notification "Take a break!" with title "20-20-20 Rule"'
This uses the Mac's built-in notification system to show the message reminding you to take a break.
Next, the launchd agent (this must be saved in
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>twenty</string> <key>ProgramArguments</key> <array> <string>sh</string> <string>/Users/YOURNAME/scripts/twenty.sh</string> </array> <key>StartInterval</key> <integer>1200</integer> </dict> </plist>
And the commands:
$ launchctl load ~/Library/LaunchAgents/twenty.plist $ launchctl start twenty
And voila, you now have an automated reminder on your Mac to take a twenty-minute break and help lessen eyestrain.
If you ever want to stop the agent:
$ launchctl stop twenty
And if you ever want to change the agent settings, you'll additionally need to unload the agent and then reload and restart it to pick up the changes:
$ launchctl unload ~/Library/LaunchAgents/twenty.plist