How to I stop a launchd script from running on wake I have a simple launchd script that plays a sound every 30 minutes and it runs out of the user library ~/Library . It doesn't run if my machine is asleep, but does run the last event missed when the machine wakes. I think this is the expected behavior. My question is, how do I stop this happening. If I missed the half-hour event, I don't want it to be run at 20 minutes past the hour.

Here's the core of my script. It calls a Python script. I tried to put a block in the python script to check that I am within a few minutes of each 30 minutes, but that doesn't seem to work on wake. (Is it missing the system clock somehow?)

&lt;key&gt;ProgramArguments&lt;/key&gt;
&lt;array&gt;
    &lt;string&gt;/usr/local/bin/python3&lt;/string&gt;
    &lt;string&gt;/Users/pheon/Documents/playsound.py&lt;/string&gt;
&lt;/array&gt;

&lt;key&gt;StartCalendarInterval&lt;/key&gt;
&lt;array&gt;
    &lt;dict&gt;
        &lt;key&gt;Minute&lt;/key&gt;
        &lt;integer&gt;0&lt;/integer&gt;
    &lt;dict&gt;
        &lt;key&gt;Minute&lt;/key&gt;
        &lt;integer&gt;30&lt;/integer&gt;
    &lt;/dict&gt;
&lt;/array&gt;


Here is a snippet from the python code which checks the time before playing the sound.

time0 = datetime.datetime.now()
if (time0.minute % 30) &lt; 2:
    subprocess.run(["/Users/pheon/bin/afplay-vol.sh", "1", bell],check=True)
The problem lies with launchd and how it handles jobs that are missed during sleep:

From the launchd.plist man page (man launchd.plist)


Unlike cron which skips job invocations when the computer is asleep,
launchd will start the job 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.



So, there are a few options to consider...


revert to cron.  Though deprecated, cron won't run jobs that have been missed
check for time of day before playing the sound (this can be done with a "wrapper" script or within the script itself.
write a log entry (somewhere).  On script launch, parse the log.  If a sound was played within the last 30 mins, don't play again.