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 ~/Library/LaunchAgents/twenty.plist
):
<?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/YOURACCOUNT/scripts/twenty.sh</string>
</array>
<key>StartInterval</key>
<integer>1200</integer>
</dict>
</plist>
(Remember to change YOURACCOUNT
to your actual user account!)
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
This should be portable to other OSs:
- Linux: show desktop notifications with notify-send and manage the notification schedule with a systemd timer
- Windows: show desktop notifications with Windows Script Host and manage the schedule with Task Scheduler.
Top comments (0)