Automatically ejects an external disk after a Time Machine backup completes — no polling, zero CPU idle.
A launchd user agent watches /Library/Preferences/com.apple.TimeMachine.plist for changes (which macOS writes at the end of every backup). When it fires, the script checks tmutil status to confirm the backup is truly finished, waits briefly for backupd to let go of the disk, then ejects it via diskutil eject. It retries for about 10 minutes, aborting early if a new backup starts, and falls back to a forced unmount if everything else fails. A macOS notification is sent on success or failure.
The most common cause of "could not eject — files in use" is Spotlight: mdwrite keeps the backup volume open and dissents the unmount, sometimes for hours. install.sh detects this and offers to turn indexing off for the chosen volume. To do it by hand:
sudo mdutil -i off -d "/Volumes/Your Backup"
sudo mdutil -X "/Volumes/Your Backup"Backups aren't searchable via Spotlight anyway, so there's nothing to lose.
./install.shYou'll be shown a numbered list of mounted volumes — just pick the one to eject. The script is installed to ~/Library/Scripts/ and the launchd agent to ~/Library/LaunchAgents/. Re-running install.sh upgrades an existing install in place.
Verify it's running:
launchctl list | grep eject-tm./uninstall.shtail -f ~/Library/Logs/eject-tm.logtmutil startbackup
tail -f ~/Library/Logs/eject-tm.logThe disk will eject automatically when the backup finishes and a notification will appear.
- macOS (tested on macOS Sequoia)
- Time Machine configured with an external disk