Skip to content

Instantly share code, notes, and snippets.

@jb510
Forked from boogah/ale.bash
Last active January 20, 2022 15:42
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save jb510/99f12b1ac70f1cf8b780 to your computer and use it in GitHub Desktop.
Save jb510/99f12b1ac70f1cf8b780 to your computer and use it in GitHub Desktop.
Auto Update Brew: OS X Launchd job and script to automatically update homebrew
  1. Place homebrewupdate.sh where ever you like, I use ~/bin/homebrewupdate.sh
  2. Place the .plist file in ~/Library/LaunchAgents and update the path to your bash script
  3. run launchctl load ~/Library/LaunchAgents/com.jb510.homebrewupdate.plist or whatever you've named your plist file.
  4. check launchctl list | grep jb510 to see that it's running

Note: You might need to chmod +x homebrewupdate.sh

Note 2: you can run this manually to test your script ~/bin/homebrewupdate.sh

Future: Update this to also update casks https://github.com/buo/homebrew-cask-upgrade or using brew cask list | xargs brew cask reinstall

<?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>com.jb510.homebrewupdate.plist</string> <!-- UPDATE file name -->
<key>ProgramArguments</key>
<array>
<string>/Users/jon/bin/ale.sh</string> <!-- UPDATE file name -->
</array>
<key>Nice</key>
<integer>1</integer>
<key>StartInterval</key>
<integer>21600</integer> <!-- UPDATE interval in seconds -->
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/tmp/jb510.homebrewupdate.err</string> <!-- UPDATE name/path -->
<key>StandardOutPath</key>
<string>/tmp/jb510.homebrewupdate.out</string><!-- UPDATE name/path -->
</dict>
</plist>
#!/bin/bash
echo ""
echo "`date`: RUNNING: brew update"
/usr/local/bin/brew update
echo "`date`: FINISHED: brew update"
echo ""
echo "`date`: RUNNING: brew upgrade"
/usr/local/bin/brew upgrade
echo "`date`: FINISHED: brew upgrade"
echo ""
echo "`date`: RUNNING: brew cleanup"
/usr/local/bin/brew cleanup
echo "`date`: FINISHED: brew cleanup"
echo ""
echo "All done! Enjoy a cold one! 🍺 "
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment