What This Script Does

The auto-update-brew.sh script automates the routine maintenance of your Homebrew packages. Keeping your packages up to date is important for security patches, bug fixes, and access to new features, but remembering to run updates manually can be tedious. This script handles the entire update cycle automatically and sends you a text message summary when it finishes, so you always know the current state of your system without having to check manually.

Before performing any updates, the script runs a series of pre-flight checks to ensure conditions are appropriate for an unattended update. The first check verifies your Wi-Fi connection: the script compares your current network name against WIFI_NETWORK, which is set at the top of the script. This keeps large downloads off a metered hotspot or public Wi-Fi. If the network does not match, the script texts you a "Skipped" notice, logs the reason and exits without updating.

The second pre-flight check examines your Mac's power status. Running package updates can be CPU-intensive and may take several minutes, which is not ideal when your Mac is running on battery power. AC power is required: if your Mac is on battery, the update is skipped until the next scheduled run.

Once the pre-flight checks pass, the script runs four Homebrew operations in sequence: brew update, brew upgrade, brew upgrade --cask and brew cleanup. First, it runs brew update, which downloads the latest package index from Homebrew's repositories. This tells Homebrew what new versions are available but does not install anything yet. Second, brew upgrade and brew upgrade --cask install newer versions of outdated formulae and apps, with their output written to the log. Finally, brew cleanup, which removes old versions of packages that are no longer needed and clears the download cache to free up disk space.

When the operations finish, the script builds a short summary: the time, the number of successful operations, the number of errors, and whether everything succeeded. The summary is then sent to your phone as an iMessage text message using macOS's built-in osascript command to interface with the Messages app. This gives you a quick at-a-glance notification that your system is up to date.

The script is designed to be run either manually or on a schedule via launchd. When run manually, you see all output in real time in your terminal. When run on a schedule, the output is captured in a log file and the text message notification serves as your primary status report. For scheduling, see the Schedule Auto-Updates script, which automates the creation of the launchd agent.

Usage

You can run this script manually at any time, or schedule it to run automatically using the setup-auto-update.sh script.

# Preview what would be updated (no changes made)
./auto-update-brew.sh --dry-run

# Run the update immediately
./auto-update-brew.sh

When running manually, you will see progress output in your terminal as each Homebrew operation completes. The text message notification is sent at the very end, after all operations have finished.

Options and Flags

Flag Description
--dry-run Check the Wi-Fi and power conditions and list outdated packages and casks, without upgrading anything, writing the log or sending a text. --check is an alias.

Configuration

There is no config file for this script. These values are hardcoded near the top of auto-update-brew.sh; edit them there:

Setting Effect
WIFI_NETWORK The Wi-Fi network updates are allowed on. Edit WIFI_NETWORK at the top of the script; left as the placeholder, every run skips. There is no option to skip this check.
PHONE_NUMBER Your iMessage-compatible phone number for receiving text message notifications. Include the country code (e.g., +1 for US numbers). Schedule Auto-Updates writes this for you.

AC power is always required; there is no setting to turn that off. If the text message cannot be sent (Messages not signed in, or your terminal not allowed to control it under System Settings > Privacy & Security > Automation), the script logs the failure and finishes the run. All results are recorded in the log either way.

What Gets Changed

  • Homebrew packages — All installed formulae and casks are updated to their latest available versions via brew upgrade.
  • Old package versions — Previous versions of upgraded packages are removed by brew cleanup to reclaim disk space.
  • Download cache — Cached installer files in Homebrew's download directory are cleared during the cleanup phase.
  • iMessage — A text message is sent to your configured phone number via the macOS Messages app. This uses AppleScript and does not require any third-party services or API keys.
  • Log file — Every run is appended to ~/Library/Logs/AutoUpdateBrew.log, including the full Homebrew output and any errors.

Related Scripts

  • Auto-Update with Email & Text — An enhanced version of this script that also sends a detailed email report in addition to the text message summary.
  • Schedule Auto-Updates — Automates the creation of a macOS launchd agent so this script runs on a recurring schedule without manual intervention.