Skip to content

Instantly share code, notes, and snippets.

@streeter
Last active March 2, 2022 17:57
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save streeter/3254906 to your computer and use it in GitHub Desktop.
Save streeter/3254906 to your computer and use it in GitHub Desktop.
Homebrew Package Update Notifications on Mountain Lion
#!/bin/bash
#
# Notify of Homebrew updates via Notification Center on Mac OS X
#
# Author: Chris Streeter http://www.chrisstreeter.com
# Requires: terminal-notifier. Install with:
# gem install terminal-notifier
TERM_APP='/Applications/Terminal.app'
BREW_EXEC='/usr/local/bin/brew'
TERMINAL_NOTIFIER=`which terminal-notifier`
NOTIF_ARGS="-activate com.apple.Terminal"
$BREW_EXEC update 2>&1 > /dev/null
outdated=`$BREW_EXEC outdated | tr ' ' '\n'`
if [ -z "$outdated" ] ; then
if [ -e $TERMINAL_NOTIFIER ]; then
# No updates available
$TERMINAL_NOTIFIER $NOTIF_ARGS \
-title "No Homebrew Updates Available" \
-message "No updates available yet for any homebrew packages."
fi
else
# We've got an outdated formula or two
# Nofity via Notification Center
if [ -e $TERMINAL_NOTIFIER ]; then
lc=$((`echo "$outdated" | wc -l`))
outdated=`echo "$outdated" | tail -$lc`
message=`echo "$outdated" | head -5`
if [ "$outdated" != "$message" ]; then
message="Some of the outdated formulae are:
$message"
else
message="The following formulae are outdated:
$message"
fi
# Send to the Nofication Center
$TERMINAL_NOTIFIER $NOTIF_ARGS \
-title "Homebrew Update(s) Available" -message "$message"
fi
fi
@tmitchell
Copy link

Works great, thanks for the gist! One fix: line 7 should be # gem install terminal-notifier

@streeter
Copy link
Author

Thanks!

@jbarratt
Copy link

Alternatively you could do brew install terminal-notifier, which since this tool is targeting brew users, seems like has better odds of working out of the box.

@SimonSimCity
Copy link

I've extended the script to exclude pinned formulae in the list of outdated formulas:

https://gist.github.com/SimonSimCity/13832e2e03597a6be793

@todmephis
Copy link

todmephis commented Jul 27, 2018

Added some new features on my forked version. macOS High Sierra
https://gist.github.com/todmephis/832796f8d5b148efa89df4ca7c63a1b4

Thanks @streeter. Great script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment