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?
Ask Different is a question and answer site for power users of Apple hardware and software. It only takes a minute to sign up.
Sign up to join this communityYou 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
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.
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.