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?)
<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)
macos sleep-wake launchd
add a comment |
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)
macos sleep-wake launchd
add a comment |
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)
macos sleep-wake launchd
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)
macos sleep-wake launchd
macos sleep-wake launchd
edited Dec 6 at 20:59
bmike♦
156k46282606
156k46282606
asked Dec 6 at 14:15
pheon
2301414
2301414
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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 missedcheck 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.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "118"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fapple.stackexchange.com%2fquestions%2f344897%2fhow-to-i-stop-a-launchd-script-from-running-on-wake%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 missedcheck 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.
add a comment |
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 missedcheck 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.
add a comment |
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 missedcheck 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.
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 missedcheck 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.
answered Dec 6 at 17:17
Allan
41.9k1360154
41.9k1360154
add a comment |
add a comment |
Thanks for contributing an answer to Ask Different!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fapple.stackexchange.com%2fquestions%2f344897%2fhow-to-i-stop-a-launchd-script-from-running-on-wake%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown