Is it possible to search a macro group for CRON triggers that are due to trigger between 2 dates?

I use a lot of CRON based reminder macros (simple display text in window +/- sound). The are all stored in the same group. At the beginning of every week, I would like to have a look at all upcoming CRON triggered macros.
thanks in advance for your time and help

I don't know if there's a way to peak at KM's "upcoming jobs" list -- or even if it has one! But you can get all your cron-triggered macros with the following AppleScript:

tell application "Keyboard Maestro"
	set theGroup to item 1 of (every macro group whose name is "cronGroup")
	set theMacros to (every macro of theGroup)
	repeat with eachItem in theMacros
		copy {name:name of eachItem, trigger:description of trigger of eachItem} to end of cronList
	end repeat
end tell
return cronList

If you run that in Script Editor, after changing "cronGroup" in line 2 to the name of the group holding your cron-triggered macros, you get a name/trigger list:

{{name:"Mail Test", trigger:{"Cron entry “0 0 -1 1 +1 2017” matches current time"}}, {name:"test Var Del", trigger:{"Cron entry “0 0 -1 1 +1 2017” matches current time"}}}

You could then parse that list, checking the "trigger" entries for items that would trigger in the coming week and returning the macro names.

I won't lie -- that is going to be a tricky search to do, and very dependant on the complexity of your cron entries! "@weekly" and similar will be easy enough, as will "n n * * *" (ie things that trigger every day) or "n n * * n" (ie things that trigger of a day of the week). After that it could get very complicated, very quickly.

But it might show you a way forward if nothing else is presented.

1 Like

thank you so much for your post and the time it took to write the script !
I get an error message because the cronL variable is not defined

2022-04-27 14:57:52 Execute macro “CRON create list of upcoming CRON” from trigger Editor
2022-04-27 14:57:52 Action 9160669 failed: Execute an AppleScript failed with script error: text-script:194:261: execution error: The variable cronList is not defined. (-2753)
2022-04-27 14:57:52 Execute an AppleScript failed with script error: text-script:194:261: execution error: The variable cronList is not defined. (-2753). Macro “CRON create list of upcoming CRON” cancelled (while executing Execute AppleScript).

@ronald -- My apologies, it was getting late and I (stupidly) missed a line out when copying from Script Editor to the forum. But you can see from the error that "the variable "cronList" is not defined", so all we have to do is define cronList before we try to add things to the end of it. Full script (and don't forget to change "cronGroup" in line 3 to the name of your KM folder containing your cron-triggered scripts):

tell application "Keyboard Maestro"
	set cronList to {}
	set theGroup to item 1 of (every macro group whose name is "cronGroup")
	set theMacros to (every macro of theGroup)
	repeat with eachItem in theMacros
		copy {name:name of eachItem, trigger:description of trigger of eachItem} to end of cronList
	end repeat
end tell
return cronList
1 Like

thanks very much. Once again sorry for taking your time.

My objective is to display:
name of macro CRON
To be able to see the results on the screen, I tried to add the last time, but the clipboard is empty

tell application "Keyboard Maestro"
	set cronList to {}
	set theGroup to item 1 of (every macro group whose name is "Webinars")
	set theMacros to (every macro of theGroup)
	repeat with eachItem in theMacros
		copy {name:name of eachItem, trigger:description of trigger of eachItem} to end of cronList
	end repeat
end tell
return cronList
set the clipboard to cronList as text

You can search for all Cron triggered macros with a search for “trigger:cron”.

But there is no way to ask Keyboard Maestro when they will trigger next.

thank you. A search is not very useful for my purposes

Thank you -- good to know I wasn't missing the obvious (again!).

A return statement ends a script (or function), sending the included value (if any) to the process which called it. So your added line is never reached -- delete the return cronList line and the script will do what you want.

But I must ask how useful it will be. You'll get a list of every cron-triggered macro, each an item like

{name:"Mail Test", trigger:{"Cron entry “0 0 -1 1 +1 2017” matches current time"}

...and you'll have to decide for each if the cron entry contains one or more conditions that will be matched in the next 7 days. Easy enough for the above, but what about

{name:"Last Friday of even months", trigger:{"Cron entry “* * * */2 -Fri” matches current time"}

So you have to "explode" every complex cron entry to turn ranges into lists, etc. To make it worse, most "cron listers" only look for the next occurrence of a job -- you want to list any and all that happen in the next 7 days...

That's a lot of work -- work that's already been done in programs that are written to let you create events, get reminders, etc. Is there some reason why you are using KM for this whole workflow rather than, say, Apple's included Calendar app? Even if you simply hate using Calendar, it would be a lot simpler to use that as the "storage and reminder" part while using KM to create the reminders in Calendar!

Very good points. I now see what you mean. thank you so much for your explanations and efforts.