3

If a launchd job has a StartInterval of 600 and it's been "some time" since the plist was loaded.

How can one determine how much time remains until the next scheduled run?

3 Answers 3

2

You can't. Indeed launchd doesn't even guarantee to an interval of exactly 600 seconds, just close.

The best way to do something similar is to get your launchd task to touch a file, preferably in /var/tmp

1

It really depends on why you care (inherently, you shouldn't, or more likely, there's some better way to do it). It all comes down to your script being smarter. Drop a turd file or use the script to either defer until next run, or go into a holding pattern.

1
  • Agreed, in the running of our script, we dont' care. Jan 9, 2012 at 23:43
0

This is an old question, but on modern systems, there should be an entry in the system log (the one accessible by the log command). For example, looking at a launchd job with the label "com.apple.newsyslog", which is set to run on the 30th minute of every hour, if I run

log show --last 24h --info | grep -i newsyslog,

I see relevant entries such as:

2022-07-07 16:30:00.068603-0400 ... Running StartCalendarInterval: com.apple.newsyslog.268435460
2022-07-07 16:30:00.074442-0400 ... Rescheduling StartCalendarInterval: com.apple.newsyslog.268435460: Thursday, July 7, 2022 at 5:30:00 PM Eastern Daylight Time

So, from the log I can see when the job last ran, and when it is scheduled to run next.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .