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?)
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/python3</string>
<string>/Users/pheon/Documents/playsound.py</string>
</array>
<key>StartCalendarInterval</key>
<array>
<dict>
<key>Minute</key>
<integer>0</integer>
<dict>
<key>Minute</key>
<integer>30</integer>
</dict>
</array>
Here is a snippet from the python code which checks the time before playing the sound.
time0 = datetime.datetime.now()
if (time0.minute % 30) < 2:
subprocess.run(["/Users/pheon/bin/afplay-vol.sh", "1", bell],check=True)