Growl Notifications for Homebrew

August 25, 2011
Growl Homebrew Update

Here’s a simple script I use to update Homebrew and display a Growl notification if there are any outdated formula:

export PATH=/usr/local/bin:$PATH

# Give the network a chance to connect
sleep 10

brew update > /dev/null 2>&1
outdated=`brew outdated`

if [ ! -z "$outdated" ]; then
    growlnotify -t "Homebrew Updates Available" -m "$outdated"

To use it you’ll also need growlnotify:

brew install growlnotify

Add the script to your scheduler of choice and you’ll have one less thing to obsess about keeping up-to-date. I use a launch agent to run the check every day at 6:00 p.m. While not as simple as cron, the nice thing about launchd is that if the computer is asleep during the scheduled time the task will be performed as soon as the computer wakes up. The script’s sleep call is to give the network a chance to connect in this case. Incidentally, if anyone knows of a better way to delay execution until the system is on the network I’d love to hear about it.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">

If you’d like to use my setup you can download these files and move homebrewupdate into /usr/local/bin and net.codeworkshop.homebrewupdate.plist into ~/Library/LaunchAgents. Then load the launch agent and you should be set.

launchctl load ~/Library/LaunchAgents/net.codeworkshop.homebrewupdate.plist