Skip to content

Instantly share code, notes, and snippets.

@dulyanov
Forked from jb510/ReadMe.md
Created January 13, 2019 00:39
Show Gist options
  • Save dulyanov/cda66856d61cfb552a2ed01d9333e522 to your computer and use it in GitHub Desktop.
Save dulyanov/cda66856d61cfb552a2ed01d9333e522 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