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

I’ve been reading what I can and still need some help with buttons in the Prompt for User Input action and figuring out what can be accomplished in them.

I see that you can create more buttons by typing whatever the heck you want to in a new button field after clicking on the green plus to add a new button, but how you tie that to an action or a way of populating a Variable is something I can’t figure out. I read somewhere that buttons other than OK and Cancel populate the “Result Button” variable when pressed, but is that the ONLY variable you can use with additional buttons? I’m fairly confused.

Now let me ask about a specific example in the hopes that it will help outline what I’d like to be able to do with buttons just as an experiment to help me learn about them.

I have a variable called “Instrument Category” and it has options that I can populate it with. They are Guitars, Drums, Piano, Vocals.

I would like to create a macro that pops up and, using Prompt for User Input asks “What instrument are you recording right now?” and allows you to push the button corresponding to the instrument you desire, and have that choice populate the variable “Instrument Category”

So is this possible??
Thanks!

Just check "Result Button" for the text of the button.

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