DEV Community

Yawar Amin
Yawar Amin

Posted on • Updated on

How to set up a 20-minute computer break on a Mac

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/
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" "">
<plist version="1.0">



(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:

Top comments (0)