· 原发布于 blog.hackerpie.com

DIY an interesting timer through terminal-notifier and crontab under Mac OS X

Today I will show you how to DIY an intersting notifier automatically running per hour under the Mac OS X 10.8 and higher, all we need are a terminal-notifier and the system built-in command line program named crontab.

1. Install the terminal-notifier

terminal-notifier is a program written in the awesome Ruby program language, we can visit the releases page and download the newest version of terminal-notifier. Steps to install it:

  1. Please click the green button such as “ terminal-notifier-1.5.0.zip ” and select a path wherever you love to save the zip file;
  2. After downloading completed, open the folder you selected in the above step, look for the zip file, and then double-click to extract the program;
  3. Copy the extracted program terminal-notifier ;
  4. Click the “Applications” tab in the sidebar of your finder, and then paste the copied file.
  5. Lastly, open a terminal and then run the following command to test if the notifier has been installed successfully.
/Applications/terminal-notifier.app/Contents/MacOS/terminal-notifier -title "Test Installation" -message 'your notifier has been installed successfully!'

You will see a notification message appears. If not, re-check your installation and make sure you have finished the above steps strictly.

2. Create the timer to notice you to have a break

In order to run the notifier periodically, we use crontab, which maintains crontab files for individual users.

Now, please open your terminal again, and then type the following command, run it:

crontab -e

Append the following line to the openning file:

0 * * * * /Applications/terminal-notifier.app/Contents/MacOS/terminal-notifier -title "Guy, take a break please!" -message 'You have worked for a hour again, I suggest that you should take a break.'

Save the file and exit, your cron tasks will be updated automatically.

After every thing is finished, you will reveive the attentive message per hour. Cheers!

This post only acts like a demo, you can do more powerful works as you imagine.

Related Resources:

  1. terminal-notifier
  2. crontab
  3. crontab man page
  4. Linux Crontab: 15 Awesome Cron Job Examples