How can I run a job once a day with launchd, regardless of when the computer is on? I would like to run a shell script daily, but not necessarily at a specific time. The computer the script runs on is switched on at irregular times, and no assumptions can be made when that will be.

For that, I would like to get launchd to behave a bit like anacron: It only needs to run the job once a day, at any convenient time. 

Most posts I have seen here or on other sites describe things like "running every day at 05:00", which is not helpful for me if the machine is off at that time...

How do I write a launchd plist specifying that behaviour?
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

&lt;Key&gt;RunAtLoad&lt;/Key&gt;
&lt;true/&gt;


to your launchd plist.