What This Script Does
The setup-auto-update.sh script automates the process of creating a macOS LaunchAgent that runs the basic auto-update script on a schedule you define. Instead of remembering to run Homebrew updates manually, this script sets up the system so updates happen automatically in the background at a time that works for you. It is the recommended way to ensure your Homebrew packages stay current without any ongoing effort on your part.
macOS uses a system called launchd for managing background tasks, scheduled jobs, and system services. Launchd is similar to cron on Linux, but it is more tightly integrated with macOS and supports features like running missed jobs when the system wakes from sleep. The setup script generates a properly formatted launchd plist (property list) file and installs it as a user-level LaunchAgent, which means it runs under your user account and does not require root privileges.
When you run this script, it first asks for the phone number that should receive iMessage summaries, sends a test message to it, and writes the number into PHONE_NUMBER at the top of auto-update-brew.sh. It then offers three schedules: daily at 2:00 AM, weekly on Sunday at 2:00 AM, or manual only (no agent is created). The time is fixed; to change it, edit the generated plist.
The script generates a plist XML file that contains your schedule preferences, the path to the auto-update script, and metadata that launchd uses to manage the job. It writes this file to the standard LaunchAgents directory at ~/Library/LaunchAgents/, named com.homebrew.autoupdate.plist. After writing the file, the script registers it with launchctl bootstrap gui/$(id -u), which activates the schedule immediately.
One of the advantages of launchd over simple cron jobs is its handling of missed executions. If your Mac is asleep when a scheduled update is due, launchd runs the job when it wakes. If the Mac is shut down at that time, the run is skipped until the next scheduled slot.
If you have previously set up a scheduled update and want to change the schedule, simply run this script again. It removes the existing agent from launchd with launchctl bootout, writes a new plist with your updated choice, and bootstraps it again. This makes it easy to adjust your update frequency as your needs change over time, without needing to manually edit XML files or run launchctl commands yourself.
Before finishing, the script runs auto-update-brew.sh once as a test. That run is real: if your Mac is on the configured Wi-Fi network and on AC power, it upgrades your packages. Use ./setup-auto-update.sh --dry-run to preview everything without changing anything. The commands below verify, trigger and stop the agent.