PromptButton variable is only populated if the button is clicked, but not when triggered with keyboard

I have an action set up with OK/Cancel buttons, and an if/then statement that checks which button was clicked. It works if I click the buttons, but not if I hit the enter key to trigger the button.

Is there another way to check this?

The way you have it written, with Cancel first, then Enter = Cancel, not OK. Switch the order and it'll work. (You can verify this by putting a Display Text action after the Input action, and have it display the value of %PromptButton%.)

-rob.

1 Like

You can also explicitly define which button getting pressed with the different key commands by for instance adding / to the end of OK (as in OK/) and /. to the end of Cancel (as in Cancel/.), this way mapping the buttons to Return and Escape, respectively, whichever order you’ve placed the buttons in. (That said it is of course advisable having the buttons in the regular order.)

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

1 Like

On the Mac, it breaks UI conventions to have the Cancel button on the right.

However, it works fine as is, the only button that has a default in that case is the “Cancel” button which is the default button which means pressing Return will select it, and the PromptButton token will contain Cancel.

What are you actually trying to do, and what are you having a problem with?

Ah, thank you. The reason I switched them was because Cancel is highlighted by the UI as the focused button, which makes it appear as though hitting enter will trigger that button.

I didn't realize Space was the key that triggers buttons on OS X.

That's not really an accurate statement. Both space and return can trigger buttons in the box you are looking at. The difference is that space causes the highlighted button to trigger (the one with the blue box around it), and return causes the blue button to trigger. As far as I can recall, this practice originates decades ago, including on Windows. I remember having to explain this to my Windows-centric friends decades ago.

It might help if you create a macro that looks like this. It will make it easy for you to test what I'm saying.

image

2 Likes

This. I still find it confusing when confronted with the outlined button and blue button. Even though I know, I feel like I have to remind my brain every time.

I know. This is a confusing design, that even when I explain it to people, it seems to go in one ear and out the other. I think it's just a bad design, but it goes back decades.