Skip to content

Instantly share code, notes, and snippets.

@Cyna298
Last active July 16, 2023 05:09
Show Gist options
  • Save Cyna298/d0a6518d00aa08b8aa0efbafc82447d1 to your computer and use it in GitHub Desktop.
Save Cyna298/d0a6518d00aa08b8aa0efbafc82447d1 to your computer and use it in GitHub Desktop.
Reminder to rest your eyes
# Description: This script sets up a cron job to remind you to rest your eyes every 30 minutes
# you should take your eyes off the screen, focus on a distant object for 20 seconds
#This will help prevent eye strain and dryness.
#Check if Homebrew is installed
if test ! $(which brew); then
echo "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
# Check if terminal-notifier is installed
if test ! $(which terminal-notifier); then
echo "Installing terminal-notifier..."
brew install terminal-notifier
fi
TERMINAL_NOTIFIER=`which terminal-notifier` # cron doesn't know about $PATH, so we need to specify the full path
TITLE="Break Focus" # Title of the notification
MESSAGE="Rest your eyes for 20 seconds" # Message of the notification
SOUND="Ping" # Sound of the notification (see "Sounds" tab in Notification Center Preferences)
MINUTES=30 # Minutes between notifications
#We will use crontab to schedule the notifications. More about crontab here: http://en.wikipedia.org/wiki/Crontab
crontab -l | { cat; echo "*/$MINUTES * * * * $TERMINAL_NOTIFIER -title \"$TITLE\" -message \"$MESSAGE\" -sound \"$SOUND\" >/tmp/eye-stdout.log 2>/tmp/eye-stderr.log"; } | crontab -
#In case of any errors, you can check the log files:
# cat /tmp/eye-stdout.log
# cat /tmp/eye-stderr.log
#You can check the list of cron jobs with the following command:
# crontab -l
#To see the list of available sounds, run the following command:
# ls /System/Library/Sounds
#To edit the cron jobs, run the following command:
# crontab -e
# To remove the cron job, run the following command:
# crontab -l | grep -v $(which terminal-notifier) | crontab -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment