Prompt for User Input - Saving The User's Button-Choice to a Variable

Is it possible to store a variable from the button choice of the user input, from the "prompt for user input"?

Hey Jack,


If you want to be able to return the 'Cancel' button result then you have to uncheck 'Cancel Macro'.


User Prompt ⇢ Return Button Result v1.00.kmmacros (7.1 KB)
Keyboard Maestro Export

Hey Chris,

Need your expertise on a macro I've been using for the past few months. I use this macro to plan the day with the calendar and the To-do app side by side.

I trigger the macro using ''Periodically while logged in'' every 1 hour during morning and evening time. Lately it's getting a bit annoying to cancel the macro every few hour.

I was thinking if I already continued/ok with the macro it should store that as a variable and not trigger until the next periodic section. That was the reasoning behind asking the previous question. if I could store my user prompt to a variable then use another macro to verify the status using another macro to trigger the next periodic section.

What's the best way to achieve this ?


Do you still want to be able to use the typed string trigger, even when you've cancelled the periodic trigger for the rest of that session?

I use the set of actions below to establish if my backup macros have run during the last 24 hours, and if not then continue, but if so then to cancel.

Basically each time the macro runs, it sets the current epoch time to a global variable (DND_Current Stream Deck Backup), and checks that against another global variable (DND__Last Stream Deck Backup), and calculates if the difference between the two is greater or less than 24 hours. If the difference is less (indicating the macro has run within the last 24 hours), it cancels. If the difference is greater, it proceeds. At the end of the macro, it sets the DND__Last Stream Deck Backup variable to the current time that way the next time the macro runs, it knows when it was last ran.

You could likely adapt this to your needs.

Run this macro only if not ran in the last day.kmmacros (4.7 KB)

Macro screenshot (click to expand/collapse)

Hey Jack,

I think what I'd do is:

  • When I interacted with the macro have it set a variable flag for userInteraction to true.

  • Let it continue to run but check that flag on each run and abort if the flag is true.

  • Have a time check at the beginning of the macro, and when it was greater than 07:50 (or whatever) have it reset the flag to false.

That seems like the simplest way to adapt your existing macro.


I use the typed string trigger, when ever i need to take a glance in between.

Which is important, because it means you can't disable the macro via the dialog (then re-enable just before the next "periodic section" is due to start).

Which leaves you with @ccstone's suggestion of maintaining a global variable as a flag and aborting the macro when that variable is a certain value. Have a go at it first, but shout out if you are having difficulties.

It's a bad practice to use type-string-triggers for anything but text-substitution macros...

So I did this based on your macro provided (Thanks).

  1. If the Variable "Last_Time Recorded" is less than 8 hours, continue and execute the macro. The initial 'Periodically while logged in' triggers this macro every 1 hour to see if it's less than 8 hours.

  2. I don't understand the %TriggerBase% does. Does it just check to see if the initial trigger is a Periodic Trigger?

  3. I'm not sure if it's receptive to put the Variable "Current_Time Recorded" twice?

Periodic Trigger Macro.kmmacros (5.9 KB)

Macro screenshot (click to expand/collapse)

Yes, the TriggerBase token [Keyboard Maestro Wiki] returns what kind of trigger started the macro’s execution. It is a very handy token for macros that you want to trigger using more than one trigger, such as periodic and hotkey, or something to that effect.

I’m not quite sure I follow what you mean by “receptive”, but there’s no issue with where you have that variable in your macro... however, I just realized that you don’t even need that variable. You can use the NOW() token directly in the the calculations. See this updated example below:

Sample backups macro.kmmacros (4.2 KB)

Macro screenshot (click to expand/collapse)

1 Like

Thanks, This is been working pretty good.

1 Like

Glad to hear. Feel free to mark whichever post you feel most appropriate as the “solution” so others can see it’s been resolved.