Here’s a collection of useful command-line notification tools for Mac developers. I’ve been using these for long-running build jobs or other tasks which I’m waiting for. The three methods I describe here are voice audio, system notifications, and SMS text messaging.
Voice Audio
Voice audio is built into Mac OSX and available from the command line with the say
utility. To learn the various options, refer to the say man page (or locally just man say
).
In the simplest case, just give it a text string to read aloud:
$ say "hello"
Run this at the end of a build step (or anything else which may take a while):
$ ./gradlew test; say "build and test done"
You can also choose which of the system voices to use: OS X Yosemite: Change your computer’s voice.
System Notification
With Mavericks and later (OSX 10.9), you can do this using AppleScript’s display notification
command:
$ display notification "the build is done" with title "Builder"
To make this easier to remember, you can create a notify
command (/usr/local/bin/notify
) like this:
# !/bin/bash
/usr/bin/osascript -e "display notification \"$*\" with title \"Terminal\""
Then you can call it from the command-line like this:
$ ./gradlew dist; notify "Build complete"
This idea is cribbed from this great answer on AskDifferent.
SMS Text Messaging
Finally, we have text messaging. The above two options are useful when you’re at your computer, but if you want to be notified regardless of where you are, text messaging is perfect.
There are a few different options for text messaging from the command line (Google Search for ‘command line text message’ to see a few), but I prefer to use Twilio. It’s much cleaner than some solutions (especially the ones which rely on mobile carriers’ email-to-SMS gateways) and it’s quite cheap ($1/month for a phone number and $0.0075/message).
To set it up, visit the Twilio Labs Bash SMS example page to download the script, configure with your account details, and see the usage patterns.
A simple example will look like this:
$ echo "Watson come here" | twilio-sms 415-555-1212
Then like the other options above you can combine it with your build commands like:
$ /run/some/long/process; echo "It is done" | twilio-sms 415-555-1212