How can I run a job once a day with launchd, regardless of when the computer is on?

Solution 1:

Launchd will run your jobs next time the mac wakes from sleep. So if you shut down your mac, this won't work. You will need to put your mac to sleep to get your daily script to run when the mac wakes if the last time it should have run was during the sleep duration.

man launchd.plist:

If the system is asleep, the job will be started the next time the computer wakes up. If multiple intervals transpire before the computer is woken, those events will be coalesced into one event upon wake from sleep.

Or in other words: You don't have to do anything specific, it's the default behavior anyway.

If you also want to run the command once after reboot, add

<Key>RunAtLoad</Key>
<true/>

to your launchd plist.