This Gist provides a script and a launchd configuration file to automatically update Homebrew packages and casks on a daily schedule. It uses the macOS-native launchd system, which is more reliable than cron for systems that may be asleep during a scheduled run.
-
Create the Script:
- Place the
update_brew.shfile in a directory within your user's home folder, such as~/bin/. - Make the script executable by running (
mkdir -p ~/binif you do not have this directory):chmod +x ~/bin/update_brew.sh
- Place the
-
Configure the
launchdJob:- Open the
com.user.brewupdate.plistfile in a text editor. - Find all instances of the placeholder
your_usernameand replace them with your actual macOS username (e.g.,/Users/jdoe/). - Save the modified file.
- Open the
-
Install the
launchdAgent:- Move the edited
com.user.brewupdate.plistfile into your user'sLaunchAgentsdirectory:mv com.user.brewupdate.plist ~/Library/LaunchAgents/
- Move the edited
-
Load the Job:
- Load the job into
launchdusing the following terminal command:launchctl load ~/Library/LaunchAgents/com.user.brewupdate.plist
- Load the job into
The task is now scheduled to run daily at 6:00 AM. Log files will be created at ~/Library/Logs/brewupdate.log.
To stop the automated task, run the following command:
launchctl unload ~/Library/LaunchAgents/com.user.brewupdate.plistBelow uses cron which isn't macos native: https://nopnithi.medium.com/effortlessly-automate-homebrew-updates-on-macos-24941d0213d1