I obviously google my question but it is still not clear.
thanks in advance for your time and help
This is not generally achievable with cron
with a single command (although IIRC there are some implementations that can set a start date).
Assuming this is a KM macro cron
schedule, try setting your actual macro to run every three months on the 15th but leave it disabled. Then have another scheduled to run daily from, say, the 7th to 15th September and which has an action to enable the "main" macro.
Untested, but should work...
You are a genius! Thank you!
Can you think of a way to "attach" both actions, just to make things less confusing for me in the future?
Thank you.
Short of giving them similar names and putting them in a Group? Not really.
There are other ways to do this though, if you want to keep things in one place. You could set two cron
triggers on the macro, one which did "every 3 months for the years 2024-2099" and another that was "Sept or Dec in 2023". Or you could have it running every 3 months, regardless of the year, and a first action to "Cancel this macro if date today is before 2023-09-15".
Now I've thought of it I'd probably go with the "two cron
triggers" option. It's a bit more overhead now because the macro is enabled and so there's an unnecessary "trigger check" (I don't know how often that happens -- it might be every minute, or the engine may "sleep" until the next due job or a refresh event) but it's probably the cleanest and least confusing solution.
Great ideas: I will play around with those many options.
Thanks again.
I often create macros with cron triggers.
Would you know if there is a way to avoid all the clicking, i.e. a keyboard shortcut (AppleScript?) that would create the cron trigger and insert a dummy trigger like 30 04 08 Feb * 2023 which I would subsequently modify.
Thank you.
I don't know if this is any easier than clicking the "+" button, typing CR
, and hitting Return, but:
set theXML to "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
<key>Cron</key>
<string>0 0 -1 1 +1 2017</string>
<key>MacroTriggerType</key>
<string>Cron</string>
</dict>
</plist>"
tell application "Keyboard Maestro"
set theMacros to (get selected macros)
if (count of theMacros) = 1 then
tell item 1 of theMacros
make new trigger with properties {xml:theXML}
end tell
else
display dialog "Please select one, and only one, macro"
end if
end tell
...will do what you want.
Fantastic ! Now I can add multiple cron triggers in sequence as I often do, without all the clicking around. Thanks very much. Should go in the macro library. You are incredible !
I use your macro / script multiple times a day. it is extremely useful.
I was wondering how to edit:
<string>30 04 09 Mar * 2023</string>
so that the default:
- Remains 30 04 for the time (4:30 am)
- But change the date to current date, ie date at which the add cron trigger macro is run,
Thanks very much
Build a cronStamp
from current date
and use that when constructing the XML. In long form:
set dateObj to (current date)
set theMonth to (month of dateObj as number)
set theDay to day of dateObj
set theYear to year of dateObj
set cronStamp to "30 4 " & theDay & " " & theMonth & " * " & theYear
set theXML to "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
<key>Cron</key>
<string>" & cronStamp & "</string>
<key>MacroTriggerType</key>
<string>Cron</string>
</dict>
</plist>"
tell application "Keyboard Maestro"
set theMacros to (get selected macros)
if (count of theMacros) = 1 then
tell item 1 of theMacros
make new trigger with properties {xml:theXML}
end tell
else
display dialog "Please select one, and only one, macro"
end if
end tell
(Doing it like that avoids issues with OS Date/Time settings, language, etc.)
thanks very much !