Growl Notifications for Homebrew
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"
fi
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" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>net.codeworkshop.homebrewupdate</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/homebrewupdate</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>18</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
<key>StandardOutPath</key>
<string>/dev/null</string>
<key>StandardErrorPath</key>
<string>/dev/null</string>
</dict>
</plist>
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