Skip to content

Instantly share code, notes, and snippets.

@yugoslavskiy
Last active March 25, 2017 16:36
Show Gist options
  • Save yugoslavskiy/0f3c112c499a74a35ad8e635744942fe to your computer and use it in GitHub Desktop.
Save yugoslavskiy/0f3c112c499a74a35ad8e635744942fe to your computer and use it in GitHub Desktop.
A brew update daemon for macOS

Brew update daemon

Usually, I update brew/cask tools using bash function with a commands listed below:

brew update
brew upgrade
brew cleanup --force
brew cask cleanup --force
brew prune
find /Library/Caches/Homebrew/ -type f -ls -delete 2> /dev/null

To create a daemon, save this text to ~/Library/LaunchAgents/com.example.homebrew-upgrade.plist:

<?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.example.homebrew-upgrade</string>
  <key>ProcessType</key>
  <string>Background</string>
  <key>ProgramArguments</key>
  <array>
    <string>/bin/sh</string>
    <string>-c</string>
    <string>/usr/local/bin/brew update &amp;&amp;
            /usr/local/bin/brew upgrade &amp;&amp;
            /usr/local/bin/brew cleanup --force &amp;&amp;
            /usr/local/bin/brew cask cleanup --force &amp;&amp;
            /usr/local/bin/brew prune &amp;&amp;
            /usr/bin/find /Library/Caches/Homebrew/ -type f -ls -delete 2> /dev/null </string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>StandardErrorPath</key>
  <string>/tmp/com.example.homebrew-upgrade.stderr</string>
  <key>StandardOutPath</key>
  <string>/tmp/com.example.homebrew-upgrade.stdout</string>
  <key>StartCalendarInterval</key>
  <array>
    <dict>
      <key>Hour</key>
      <integer>8</integer>
    </dict>
  </array>
</dict>
</plist>

And run the daemon:

launchctl load ~/Library/LaunchAgents/com.example.homebrew-upgrade.plist

You're awesome!

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