Thursday, January 2, 2014

Notify from the Command Line

There’s no official way of making a notification pop-up appear from the command line. This would be useful to send a message that a certain command has completed, for example. The good news is that you can use a Ruby gem called terminal-notifier to do so (gems are extensions to the Ruby programming language that’s included with OS X). To install terminal-notifier, open a Terminal window in the usual way, and type the following:

sudo gem install terminal-notifier

Type your password when prompted. Installation should take seconds.

Using terminal-notifier is easy. Just use the -message command option to specify the message, which should appear within quotation marks (or be escaped in the usual way), and use the -title option to specify the title of the notification dialog. Here’s an example:

terminal-notifier -message "Mac Kung Fu goes places other books don't dare" -title "Mac Kung Fu"

You can also specify things to happen when the notification dialog is clicked: using -open, you can specify a URL (which must include its http:// component), for example. You can find more information at the GitHub site for terminal- notifier.