Skip to content

Instantly share code, notes, and snippets.

@denvazh
Last active March 17, 2023 16:38
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save denvazh/d077bc6d37e900f92250 to your computer and use it in GitHub Desktop.
Save denvazh/d077bc6d37e900f92250 to your computer and use it in GitHub Desktop.
Scheduled update for homebrew

Scheduled updates for homebrew

This two launchdaemon scripts provide scheduled updates and upgrade for homebrew packages.

It will run in the following way:

  • brew update every day at 12:10
  • brew upgrade every day at 12:20

How to install

Create directory to store logs:

$ sudo mkdir -p /var/log/homebrew

There are two options for running those scripts.

For specific user

This will run tasks only when user is logged in.

  1. Put both files to ~/Library/LaunchAgents/
  2. Load both plist files using launchctl load providing absolute path to the plist file

For all users

This way it is possible to run updates regardless of any user active login session. This method, however requires admin privileges, thus run commands below with sudo.

  1. Put both files to /Library/LaunchDaemons/
  2. Fix permissions chmod 644 /Library/LaunchDaemons/*.plist
  3. Make sure that owner is root:wheel by running chown root:wheel /Library/LaunchDaemons/*.plist
  4. Load both plist files using launchctl load providing absolute path to the plist file
<?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.brew.update</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/brew</string>
<string>update</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>12</integer>
<key>Minute</key>
<integer>10</integer>
</dict>
<key>StandardErrorPath</key>
<string>/var/log/homebrew/update.log</string>
<key>StandardOutPath</key>e
<string>/var/log/homebrew/update.log</string>
</dict>
</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.brew.upgrade</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/brew</string>
<string>upgrade</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>12</integer>
<key>Minute</key>
<integer>20</integer>
</dict>
<key>StandardErrorPath</key>
<string>/var/log/homebrew/upgrade.log</string>
<key>StandardOutPath</key>e
<string>/var/log/homebrew/upgrade.log</string>
</dict>
</plist>
@swrobel
Copy link

swrobel commented Dec 11, 2015

Thanks for this! FYI, there's an extra e at the end of line 23 of each file that causes it to fail parsing.

@mysticaltech
Copy link

Indeed, that's great but please fix the trailing e on line 23.

@sourcecodemage
Copy link

I forked and removed the trailing e's . feel free to merge back into this one. My fork of this gist

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