How can I enter a Macro Run Time without opening KM Editor?

Maybe there is a simple way of doing this, but I've not found it. Basically, I want to activate a KM macro at a specific time and date. I've used the cron trigger, but it requires that I open KM editor and enter the correct time and date.

I've used a loop to wait until that time and date is current, but that keeps a KM process running all the time in the background? I can't do that in many cases.

Ideally, I would want to trigger KM macro (call it #1), have it be a KM dialog box just to enter the start time (and date) and save it as a string variable.

I would want that string variable to be the cron trigger on KM macro #2.

Is this possible? It doesn't seem that that the cron trigger field can accept a KM variable.

Thanks for any help or suggestions.

Do you need to run this as a certain time once or a certain time each week, or something else?

You can call Keyboard Maestro macros via osascript and launchd on a repeating basis, but I'd need to know what schedule you're on to try to suggest a solution.

There are many ways to schedule tasks. If you don't want to use the KM Editor (although you didn't say why, so this thread may be a red herring) then I can still think of several other ways.

Tjluoma covered one of the ways. You can use a macOS app like launchd (or possibly crontab) to schedule a command that will activate a macro in the KM Engine. Tj recommended that you use osascript but I think that using a Remote Trigger may also be very viable.

And thinking beyond that approach, I can think of two other ways.

One way is to use the macOS Calendar app (!!!) which can schedule a command using a feature called Calendar Alarm. I can think of at least two different ways to trigger the macro using a Calendar Alarm. Are you interested in this approach? I'm not sure why it's any "better" than using the KM Editor. Can you explain why the KM Editor is not acceptable?

If you are willing to use a Calendar event, there are probably several ways to subsequently trigger a KM macro. One is to have the Calendar Event open an Automator file which uses an action to trigger the KM macro. And I can think of two possible ways to accomplish that, which I won't mention unless you want to hear them.

Another completely different way is to have your >>iPhone<< schedule a timed event using the Shortcuts app, (timed shortcuts are available in iOS but not macOS) and then create an automation, specifically a personal automation, where you select the time and day. That should look like this:

But then you have to use a method to trigger the macro. I can think of two ways: (1) use the "Run Script over SSH action", or (2) use the "Open URL" action to open the link to a remote trigger to your macro.

So that's a lot of possible ways. It was fun trying to think of an answer for you. Do any of these approaches appeal to you?

It seems like you would like to be able to set the cron date of the macro to a new time after/when it triggers the macro, but instead changing the trigger of the macro in the Editor, you'd like to just enter it into an input dialog from wheever you are and have that value become the new time for the macro's cron trigger? If you don't mind the Editor running the background and then quitting, give this macro a try.

It has a Cron trigger and an input dialog to enter the new time, which runs separate from the Cron actions when a Hot Key trigger is pressed (I've set it to Shift+F8) Change the HotKey to what works for you. Just make sure it appears below the Cron trigger. Unnest the actions in the If Then Else action to have it also run when the Cron trigger runs.

Place your Cron actions below the If Then Else action. They will run when the Cron trigger is triggered. Press the hot key to set the Cron trigger to a new time.

No, it doesn't seem to.

This macro uses the Keyboard Maestro AppleScript to reset the xml of the first trigger of the Cron macro, which will launch/run in the Editor in the background. The macro is set to quit the Editor when it finishes. Hopefully this is not too obtrusive, but this is probably the safest way to set the trigger xml of an macro.

I've not included any error checking for the new time value, so if the value is invalid, the new invalid time will be entered and the Cron trigger won't respond. You'll have to go the Editor and check the text under the Cron trigger field to see the invalid message.

If I've got this all wrong, apologies. Considering @Airy 's follow-up questions may help you to make the task clearer.

Screenshot

Set Cron Trigger Date.kmmacros (6.4 KB)

Thank you for those ideas. They're interesting ideas, but I'd rather just use KM if I could.

Yes, that's exactly my interest. I appreciate your providing the applescript, but if I'm going to leave the KM editor open in the background, I might was well just enter in a new cron trigger string right in the KM editor.

You've confirmed my suspicion that the cron trigger won't accept a global string variable. That would be an incredible feature. Perhaps Peter could consider it for a next version?

FYI, a number of time-related issues with my regular macros become a focus with Daylight Savings Time. I do much with weather models, which all run in GMT (UTC) time. There's an hour time shift twice a year with DST/ST changes. I already run a what I call a DST flag variable (value = 1|0) Several macros I run use this DST flag for to adjust for time changes. It would be nice if global variables could serve as time triggers to automatically adjust for the change from ST to DST based on a DST flag.

I've never made a KM feature request, but I really think this might be useful to many people.

I've attached a copy of my simple macro (Is it DST or Standard time) just to share for those wanting to convert to UTC 00 06 12 18z for manipulating weather models.

While this macro let's me know if it's Standard time or Daylight Saving Time, I still need to manually adjust all my Time Triggers twice a year. If KM allowed variables as triggers, it could be automated with a simple separate Time Trigger macro that would make it all automatic by assigning global variables as the Time triggers.

UTC DEFAULT TIME SELECTION (DST-EST) for Eastern Time Zone.kmmacros|attachment (17.1 KB)

(It's set for Eastern Time Zone -5 UTC)

Thanks for these suggestions. I have several needs for changing time triggers and some of them are not regular enough to use launchd. Additionally, I have to make adjustments to these triggers that require knowing if it's Daylight Saving Time. But the use of launchd is an idea I hadn't thought of, so thanks for that.

I'm not the architect, so maybe I'm wrong here, but that idea doesn't sound possible, because how often would you want the KM Engine to evaluate the variable to re-set the values? The engine would basically be in an infinite loop re-evaluating every variable in every macro trigger. Do you really want the performance of the KM Engine to drop just for this feature?

If you really want the power of dynamic control of scheduling macros, I think you need to use a tool that's designed for that purpose, like crontab or launchd.

Not likely because triggers need to be highly efficient - Keyboard Maestro is designed to use a minimum of CPU when it is not running a macro (<1%).

This suggestion would mean that every time a variable changes the trigger time could change, which would require a whole bunch of recalculations.

Depending on your requirements, you can do what is desired by having a periodic trigger that runs every N minutes and checks whether the time is the trigger time, and if so performs the action and clears the “trigger time” variable.

Thank you for confirming what I was trying to say above.

Thank you, Peter, for your input on this. I understand what you're saying. You've left almost no stone unturned with this great software, so I figured there might be a good reason it's not one of the trigger options.

1 Like