1. home
  2. automation
  3. launchd-not-cron-scheduling-jobs-the-way-macos-wants

launchd, not cron: scheduling jobs the way macOS wants

Diego Alvarez Automation 2 mins read 10 comments 30 views

A laptop that sleeps through 3 a.m. never runs a 3 a.m. cron job. A launchd agent with StartCalendarInterval runs it as soon as the Mac wakes.

Agents and daemons

User agents live in ~/Library/LaunchAgents and run as you when you are logged in. Daemons live in /Library/LaunchDaemons and run as root at boot. Almost everything personal belongs in an agent.

Loading the job

launchctl bootstrap gui/$(id -u) path/to/plist loads it for the current session; bootout removes it. The older load and unload verbs still work but print deprecation warnings.

Logs

Point StandardOutPath and StandardErrorPath at files in ~/Library/Logs and Console.app will show them next to system logs.

  • Label jobs with reverse-DNS names.
  • Use absolute paths; launchd has a minimal PATH.
  • Test with launchctl kickstart -k.
dev.brewlog.brew-update.plist
<key>Label</key>
<string>dev.brewlog.brew-update</string>
<key>ProgramArguments</key>
<array><string>/opt/homebrew/bin/brew</string><string>update</string></array>
<key>StartCalendarInterval</key>
<dict><key>Hour</key><integer>9</integer></dict>

There are only two hard things in Computer Science: cache invalidation and naming things.

Phil Karlton, as quoted by Tim Bray

A plist with a syntax error fails silently. Run plutil -lint on it before loading.

$ cat /comments 10

O
Ola Nordmann Sep 19, 2026 · 7:00 PM

Finally someone explains this without assuming I already know it.

R
Ravi Menon Sep 19, 2026 · 8:23 PM

Nice pick. Already set it on both displays.

C
Chidi Eze Sep 19, 2026 · 9:40 PM

Printed this out and stuck it next to my desk. Old habits.

E
Elif Kaya Sep 20, 2026 · 7:56 AM

Would this work with fish instead of zsh?

K
Kenji Mori Sep 20, 2026 · 11:06 AM

Small typo in the second paragraph, but otherwise perfect.

D
Diego Alvarez author Sep 20, 2026 · 12:11 PM

Yes, it works the same way. I will add a note about it.

M
Marco Bellini Sep 20, 2026 · 11:56 AM

This is exactly the write-up I needed this week. Bookmarked.

D
Diego Alvarez author Sep 20, 2026 · 1:34 PM

Glad it helped. Let me know if anything breaks after the next update.

G
Grace Kim Sep 20, 2026 · 3:50 PM

Good question, I would like to know too.

N
Nina Petrova Sep 20, 2026 · 12:09 PM

Tried this on an M1 Air and got the same numbers within a few percent.

$ echo "leave a comment"