--- title: "Why Your Mac's Scheduled Jobs Don't Run When the Lid Is Closed" author: "Pradeep Kumar" published: "2026-11-29T07:12:36.034Z" updated: "2026-11-29T07:12:36.034Z" url: "https://zyvop.com/why-your-mac-s-scheduled-jobs-don-t-run-when-the-lid-is-closed-2lrqn" canonical: "https://zyvop.com/why-your-mac-s-scheduled-jobs-don-t-run-when-the-lid-is-closed-2lrqn" tags: ["launchd","automation","cron","macos","scheduling"] --- # Why Your Mac's Scheduled Jobs Don't Run When the Lid Is Closed Cron silently skips runs while your MacBook sleeps. Learn how launchd catches up on wake, how pmset schedules a wake-up, and how to verify it worked. ![Cover image]() You set up a nightly backup, closed the laptop, and went to bed. In the morning: nothing. No log, no error, no backup. This isn't a cron bug. A sleeping Mac doesn't run your scheduled jobs, so what matters is what your scheduler does about the runs it missed. Cron forgets them. launchd, the scheduler built into macOS, can catch up. And neither one wakes the machine on its own, which is where `pmset` comes in. ```mermaid flowchart TD A["Scheduled time arrives"] --> B{"Is the Mac awake?"} B -->|"Yes"| C["Job runs on time"] B -->|"No, asleep"| D{"Which scheduler?"} D -->|"cron"| E["Run is skipped for good"] D -->|"launchd StartInterval"| F["Interval is missed"] D -->|"launchd StartCalendarInterval"| G["Runs once when the Mac next wakes"] ``` ## What each scheduler does with a missed run - **cron:** skips the run. There is no catch-up. (On recent macOS versions, cron may also need Full Disk Access to touch protected folders like Documents.) - **launchd** `StartCalendarInterval`**:** Apple's man page says that, unlike cron, launchd starts the job the next time the computer wakes. If several runs were missed, they're coalesced into **one** run. - **launchd** `StartInterval`**:** don't rely on it for catch-up. Apple's launchd.plist man page says an interval that passes while the Mac is asleep is missed. Use `StartCalendarInterval` with fixed times instead. - **Shut down is not the same as asleep.** launchd only makes up runs missed during _sleep_. A run scheduled while the Mac was powered off isn't made up when it boots, unless the job also sets `RunAtLoad`. - **Neither scheduler wakes a sleeping Mac.** Waking is a separate job, handled by `pmset`. ## Fix 1: use launchd with `StartCalendarInterval` Create `~/Library/LaunchAgents/com.example.nightly-backup.plist`. Use your own label and absolute paths, because launchd doesn't run these values through a shell, so `~` and `$HOME` can't be relied on: ```xml Label com.example.nightly-backup ProgramArguments /bin/bash /Users/you/bin/nightly-backup.sh StartCalendarInterval Hour 3 Minute 0 StandardOutPath /Users/you/Library/Logs/nightly-backup.log StandardErrorPath /Users/you/Library/Logs/nightly-backup.log ``` Load it and test it right away instead of waiting for the scheduled time: ```bash plutil -lint ~/Library/LaunchAgents/com.example.nightly-backup.plist launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.example.nightly-backup.plist launchctl kickstart gui/$(id -u)/com.example.nightly-backup # run it now launchctl print gui/$(id -u)/com.example.nightly-backup | grep -E "state|runs|last exit" ``` After editing the plist, unload and reload it: ```bash launchctl bootout gui/$(id -u)/com.example.nightly-backup launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.example.nightly-backup.plist ``` ### Make the script safe to run late Because launchd runs a missed job at wake time, your script may start hours after its scheduled time, when you open the lid. Because missed runs are coalesced, it also won't run ten times after a long trip. Write the script so that "late" and "twice" are both harmless: ```bash #!/bin/bash set -eo pipefail export PATH="/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin" # launchd's PATH is minimal state="$HOME/.local/state/nightly-backup" mkdir -p "$state" today=$(date +%F) # Already done today? Then do nothing. [ "$(cat "$state/last-run" 2>/dev/null)" = "$today" ] && exit 0 caffeinate -i rsync -a ~/Projects/ /Volumes/Backup/Projects/ echo "$today" > "$state/last-run" # only written if the backup succeeded ``` The stamp file is written only after success, so a failed run doesn't count as done. `caffeinate -i` asks macOS not to idle-sleep until the command finishes. ### launchd gotchas - **Always set** `Minute`**.** In `StartCalendarInterval`, missing keys act as wildcards. A dict with only `Hour` set runs the job every minute of that hour. - **A LaunchAgent only runs while you're logged in.** With no user session (login window, headless, SSH only), the agent isn't loaded. A LaunchDaemon in `/Library/LaunchDaemons` runs as root at boot, but it's a different setup and needs a `UserName` key if the job must touch your files. - **Use absolute paths and set** `PATH`**.** launchd doesn't load your shell profile, so Homebrew tools won't be found unless you add their directory. ## Fix 2: wake the Mac before the job launchd catches up when the Mac wakes. To make sure it wakes at a useful time, schedule a wake a few minutes before the job: ```bash sudo pmset repeat wake MTWRFSU 02:55:00 # every day at 02:55 pmset -g sched # confirm it was saved sudo pmset repeat cancel # remove the repeating schedule ``` For a one-off wake, use `schedule`, with the date in `MM/dd/yy HH:mm:ss` form: ```bash sudo pmset schedule wake "11/30/26 02:55:00" ``` A few things to know: - `repeat` **stores one schedule.** Running it again overwrites the previous one, so put all your wake, sleep and shutdown events in a single command. - **Prefer** `wake` **over** `wakeorpoweron`**.** `wakeorpoweron` can also boot a Mac that's fully shut down, but a LaunchAgent can't run until someone logs in, and FileVault disables automatic login. A wake from sleep avoids that. - **Plug the Mac in overnight while you test.** It removes battery behavior as a variable, and keeping a lid-closed Mac awake needs power anyway. - **The wake may be brief.** Depending on the Mac and macOS version, a scheduled wake can be a short "dark wake" with the screen off, and the Mac may go back to sleep soon after. Wrapping your work in `caffeinate` (as in the script above) asks macOS to stay up until it's done, but keep the job short and test it. ## Check what actually happened overnight Don't assume it worked. Look: ```bash pmset -g log | grep -E "Wake|Sleep" | tail -20 # when did the Mac sleep and wake? launchctl print gui/$(id -u)/com.example.nightly-backup | grep -E "runs|last exit" tail -n 20 ~/Library/Logs/nightly-backup.log ``` If `runs` is higher than yesterday and `last exit code` is 0, the job ran and succeeded. ## The honest limits of "lid closed" - **A closed lid on battery means sleep.** That's the default, and it's what stops everything. - **The behavior isn't fully documented and varies.** One developer on Apple's forums reports (macOS 15 and 26) that a MacBook asleep with the lid open ran calendar jobs during dark wakes, but with the lid closed, jobs waited until the lid was opened. Other users report `pmset` wakes failing on recent macOS versions after longer sleeps. Test on your own Mac and macOS version, and re-test after major OS updates. - **Staying awake with the lid closed** generally needs clamshell mode: power adapter, external display and keyboard or mouse connected. So a laptop that sleeps in a bag can't be a reliable scheduler. If a job really must run every night, move it to something that's always on, such as a Mac mini, a Raspberry Pi or a small VPS. Use the launchd and `pmset` setup for jobs that can run "late but at least once". ## Don't rely on it silently Whichever route you pick, make failure visible. Have the script ping a dead-man's switch such as Healthchecks.io when it finishes, or send a push alert through ntfy when it fails. A job that quietly stops running is the problem you started with. ## Checklist 1. Replace cron with a launchd agent using `StartCalendarInterval`, with both `Hour` and `Minute` set. 2. Make the script idempotent: it should be safe to run late, and safe to run twice. 3. Schedule a wake a few minutes earlier with `pmset repeat wake`, and keep the Mac plugged in. 4. Wrap the work in `caffeinate -i` and keep it short. 5. Verify with `pmset -g log` and `launchctl print` the next morning. 6. Add an alert for the day it fails.