Using buttons in Prompt for User Input for things other than OK and Cancel

Hey @KMsoundguy,

That’s only for the buttons. There are a number of features available in Prompt for User Input actions.

Check-boxes, fillable fields with default values…

https://wiki.keyboardmaestro.com/action/Prompt_for_User_Input

-Chris

@DanThomas has showed you how to do this with buttons.
Here is another approach using a popup menu which might work better if you want to take advantage of having a default value remembered from the prior selection:

Here's the action:

The Default Value is set to:

%Variable%Instrument Category%|Guitars|Drums|Piano|Vocals

In this Action, your use the "Instrument Category" variable so it is automatically set to whatever the user chooses in the popup menu.
The next time you run the macro, it will default to the choice picked previously.

Thanks everyone. I actually did learn about the pop up menu yesterday and it’s great. I just wanted to learn about the buttons as well.

Is the topmost button name in a macro always going to be the button that’s highlighted in blue when you run the macro?

Is there any way to make it so that the button that’s highlighted represents the current value of that variable?

Use a variable instead of a constant in the Button name field:

Not exactly what I meant. If the options are Guitars Drums Piano Vocals and each of those words has a button, let’s say a user pushes Piano. The next time the macro is run to change it to something else, is there any way to have the Piano button highlighted in blue to show that it was the last-used choice?

You probably could, but it would take a lot of work, and the potential for a lot of bugs. Personally, I would not go there.

Gotcha. Too bad that it’s apparently difficult. I appreciate the feedback.

You can configure a button to the the default button by setting its key to return, which you do by simply appending a / to its name.

https://wiki.keyboardmaestro.com/action/Prompt_for_User_Input#Optional_buttons_can_have_command_keys

But there is no easy way to set the default button conditionally. The best I can suggest would be tediously setting up the Prompt action once for each possible default button setting, and using a Switch or Case action to select the desired Prompt. Tedious and error prone.

Got it. Thanks much, Peter

Hey @KMsoundguy,

Peter is so right.

If you really want to do really fancy stuff in a dialog Keyboard Maestro 7 introduced the Custom HTML Prompt action which has access to HTML, CSS, and JavaScript.

It’s not for the faint of heart, but the sky is the limit.

-Chris

Thanks @ccstone and more questions for you or @peternlewis : Screenshot of an example simple macro I'm playing with to learn attached.

As is, if I hit the Escape key after bringing up this prompt, it triggers the "Top" button instead of the Cancel button and thus inputs Top into the variable. How do I ensure that the hitting the Escape key properly accesses the Cancel button?
I read about it online and tried setting the Cancel button to exactly "/.Cancel" but that just put those characters into the GUI.

Also, I tried what Peter said to use a / to make one of the buttons the default by making Top into exactly "/Top" but that doesn't work as well.

What am I doing wrong here?

It looks like a bug to me. We’ll have to wait for Peter to be sure.

-Chris

Correct. The first button (which is displayed right-most) is the default button (pressing Return will trigger it), and the second button is the cancel button (pressing Escape will trigger it).

Add “/.” to the name. I don’t know where you are seeing “/.Cancel”, the example shows “Help/H”

That said, the right most button should be the default button. If you really want Cancel, Top and Bottom, then you should have buttons:

Top/ (default) or Top/T (T)
Bottom/B (B)
Cancel/. (Escape or Command-.)

Note that if the dialog has text fields, then it would be Command-T and Command-B, but if the dialog has no text fields, it is just the letters by themselves.

It’s not a bug, the default keys are based on position not whether the Cancel option is on.

And the right0-most button should never be Cancel on a Mac, it should always be the default button.

If all you want to do is indicate which one is the last one used, you could do something simple like adding an asterisk to the beginning of the text. It wouldn’t cause it to be the default, but it would give you a visual indication of which was last used.

If you want to do this, you’ll have to have all the button names come from variables, and when you test “Button Result” you’ll want to test it against the variables, not hard-coded text.

@peternlewis Got it! All of that makes sense. / or /. needs to come at the end of the button name, not the beginning. Working as-desired now. Thanks!

Hey Peter,

Okay, then what’s the point of the cancel-option?

-Chris

The cancel option controls whether the macro is canceled when the button is pressed or whether the macro continues. So it sets the behaviour of the button.

I see. The nomenclature overlap makes it a little confusing.

-Chris

Well, to be clear:

  • The first button has a default key of Return
  • The second button has a default key of Escape/Command-.
  • Other buttons have no default key
  • Whatever button has the key Return will be the “Default” button, highlighted appropriately by the system.
  • Any button can Cancel the macro as determined by the checkbox.

The terminology for canceling a macro could have been “Abort”, but it isn’t, it’s Cancel, and it’s not really enough to change this at this point just to be clearer for this case.

In Mac OS and OS X, good UI defines:

  • the default button should be the “OK” button, the one that performs the normal behaviour
  • the default button should be rightmost
  • the left most button should be “Cancel”
  • other buttons may vary
  • If the normal behaviour is significantly dangerous, then it may be appropriate for it to not be the default button, or for there to be no default button.

“normal behaviour” here is defined as doing what the user just asked to do.

A consequence of all of this is that if you have a second button in the Prompt For User Input action, and it does not cancel the macro, then you should definitely give it some other key, or disable it with “/-”.

I will change the code so that if the first button has the Cancel Macro flag, then it is not the default (by default), and if the second button does not have the Cancel Macro flag, then it does not get the Escape/Command-, key (by default).

2 Likes

@peternlewis and all:

I have updated the Keyboard Maestro Wiki to reflect Peter’s post:
Prompt For User Input

2 Likes