Adding a dropdown (or choices) to a macro

I have a Macro that I created that fills out a bunch of information to a webpage.

The macro is working the way I want it (basically), but there is one area that I have three different options that I would enter in and right now I’m going into the macro and Disabling the two option that I don’t want or enabling the one that I do want.

Is there a way that when the macro starts it will let me chose 1 of the 3 options?

Also how do I add the Macro to this post so others can see what I have created so far?

Absolutely. This is a large part of what the Prompt for User Input action is for. Try looking that page over for now, and feel free to come back with more questions if you’re not sure how to go about incorporating its many options.

As for uploading your macro (which would definitely help us to offer better advice) you can find instructions for that here, in the “How to Post/Upload Your Macro to the Forum” section:

1 Like

I’ll mess around with the different Popup Menu’s and see what works for me.
I’m thinking just the basic Popup Menu Default maybe what I’m looking for.

I have uploaded a macro before, but it has been a while and I forgot how to
do it.

Thanks for the point in the right direction.


1 Like

I think I have the basics worked out for this.
Here is what I have come up with, but there are a few things I want to correct.
The most important is to replace the "Paste" with an actual ⌘V as in the Type the ⌘V Keystroke.
The next is something that would make thing easier.
Right now I have to use my mouse to go up to the drop down menu and choose one of the three options.
I would like to be able to use the up and down arrow key to move up and down the choice list, like the gif below.

Thank you for your help.


Keyboard Maestro “Prompt for User Input” Action

Prompt for User Input.kmactions (0.8 KB)

I'm afraid I'm a little confused about what you want to accomplish by changing "Paste" to "⌘V" in the dropdown menu. It's easy enough to simply write "⌘V" instead of paste there, but I'm guessing you want the macro to actually perform a paste if you select that option? If that's the case, it doesn't matter whether it's "Paste" or ⌘V or anything else; all you need to do is add an If Then Else or Switch/Case action to have the macro paste if the DAT__Search for variable's value is "Paste"/⌘V/anything else:

As for navigating the choice list via keyboard, I can recommend two possible methods. First, you can use either Tab or Shift-Tab to move the focus to the dropdown menu in a prompt, press Space to activate it, and use the Up and Down keys from there to select an option without using the mouse at all.
Second, you can instead use the new-to-KM8 Prompt With List to make your choice, as it's explicitly designed for keyboard navigation, including the ability to type to filter down your choices. Here's what that would look like in practice:

(the numeric prefixes were added to ensure it displays in the intended order, since Prompt With List currently always sorts the data it shows alphabetically and chronologically)

Sorry if it was confusing, but what you said is exactly what I want to do.
When I chose paste I want it to paste the information that I previously copied into that space.
I think I set it up exactly as you had it, but when I run the Macro it just puts paste in the space that I want.

As for navigating the choice list via keyboard, I tried the first option and when I run the Macro the dropdown menu is the point of focus when it comes up and is already active, but the up and down arrows have no effect on the menu.

I haven't tried the other option because I think it is above me right now and I don't have KM8 installed becasue I was having problems with the Absolute Positioning with it it seems like it works fine in an actual Macro, but when I click on the go button to double check that it is going to the correct position when I'm trying to finetune a Macro it doesn't go to any position.

Keyboard Maestro “Prompt for User Input” Action

Prompt for User Input.kmactions (0.8 KB)

Hey Steve,

I’m afraid I don’t have time to respond in depth at the moment, but in the meantime, can I ask you to post your full macro so I have a better idea of what it is you’re trying to accomplish with it? I have an idea of why your macro may be going wrong right now, but having the whole thing to look at would significantly cut down on the guesswork.

So while I’m waiting for you to post the full version of your macro, here’s a quick response to your keyboard navigation issue:

If you press the spacebar when the focus is on the dropdown menu (and since the focus is there by default, you should be able to do so as soon as you see the prompt) the menu will, uh, drop down, and you’ll then be able to navigate it with the Up and Down keys. Give it a try; I think you’ll be pleasantly surprised by how easy it is :slightly_smiling_face:

This is the full macro the only thing that is not the same as the final one being used is the instead of Option #2 and Option #3 there will be other text there, but I can't list it here.

I don't know why it is only showing this much, but I have uploaded a screenshot of the full thing.

I would think the navigating by the keyboard would be easy, but when the dropdown box is active you don't need to hit the space bar to select it, just hitting the down arrow will drop down the list, but it will not move the selection.
The same thing happens when I do hit the spacebar to select it.

Here is a gif of the dropdown menu.
I wish there was a way to show you that I'm hitting the up and down arrows.

By the way, thank you for your help.

Keyboard Maestro “Prompt for User Input” Action

Prompt for User Input.kmactions (0.8 KB)

Hey Steve,

You're quite welcome. Thanks for sharing your full macro. No worries about not including what Options #2 and #3 stand for; the important thing is to see how your macro works and what it's trying to do. As I suspected, the information you copied at the beginning isn't what's being passed through to the final paste action; as it is now, you're pasting the value of the DAT__Search for variable, which, if you select the first option in the dropdown menu, is of course "Paste." What you want to do in this case is use the Search for variable as a kind of guide for what should be pasted, rather than pasting the variable itself. Here's a reworked version of your macro with almost all the same steps (you had "Activate Chrome" twice, so I removed the redundant one) but with a different order, and it's this order that makes all the difference. (It also uses a hotkey trigger rather than a typed string since, if you're using a macro that copies the currently selected text, typing a string to trigger a macro will usually un-select the selection, whereas hotkey triggers don't have that problem).

Popup Menu Test.kmmacros (6.0 KB)

The key difference here is that I'm invoking the Switch/Case to determine what should be pasted at the point where Chrome is awaiting text to be entered. Try this version out, and hopefully it will be clear why this version works as intended (though of course, if it doesn't, feel free to let me know and I'll take another crack at it).

As for keyboard navigation: I see now that I misunderstood you before, and that you had tried my earlier advice and it didn't work as expected. Sorry for inadvertently giving unhelpful advice (twice, no less :sweat_smile:)
When trying the prompt for this reworked macro myself, I ran into the same behavior that you did, and found that you were right: sometimes, for reasons I'm unsure of, the dropdown menu in Prompt for User Input cannot be navigated with the keyboard, whether using the spacebar or the arrow keys. This seems more like a bug to me rather than the way the prompt is supposed to behave, but I'll let @peternlewis weigh in on that when he gets a chance. In the meantime, I did discover an easy workaround: just press the Escape key to revert the dropdown and try either the arrow keys or spacebar again, and the second time, it should work.

Gabe, unfortunately it doesn’t work well for me.
When I press the SPACE key it does cause the item to popup, but then it will NOT respond to further keyboard commands, like arrow up/down.

This was noted last year by another user, and while several workarounds were attempted, none seemed to always work. See Popup menu in Prompt for User Input problem.

I don’t have this issue with any other popups in any other app on my Mac, so I’m not sure why we do with KM.

@peternlewis, can this be fixed?

BTW, I’m running macOS 10.11.6, so maybe that could be a factor.

Hey Jim,

Yeah, after I wrote that post I ran into the same behavior while reworking the OP's macro (I mention it in the post right above yours) and since I'm running High Sierra 10.13.1, and the OP is using KM 7.3.1 (not to mention that other user reporting it last year) it seems that whatever is causing this issue isn't limited to either older versions of macOS or different versions of KM. In my testing, I've had consistent success using Escape to un-pop down the menu and then navigating it with the keyboard again as a workaround, but it would be great if we could track down why this behavior is occurring and have Peter fix it for good. As near as I can tell, this only seems to occur for dropdown menus that are focused by default when the prompt first appears. For prompts where a different field is focused by default, like a text entry field for a variable (example:

using Tab or Shift-Tab to navigate to them from there and then using Space or the arrow keys seems to always work as expected, at least for me on 10.13.1/KM 8.0.4.

1 Like

That works much better we are 99% there.
The only thing and again maybe it is me, but when it pastes the copied information to the Google URL it is pasting the copied information followed by Clipboard.

For example if I copy Keyboard Maestro it is pasting Keyboard%20MaestroClipboard.

The workaround for the keyboard navigation works.
Still a little bit of a pain in the butt, but better than using the mouse.
I can probably build something into the macro that will hit the escape key

I got it working.
I’m not sure what I did, but I removed the Insert Text “%Variable%” by Pasting and it works fine now.

Glad it’s working for you now, and that you resolved the added “Clipboard” text situation! My guess is that you were still including the “Insert Text %Variable%DAT__Search for% by Pasting” action after the information you had copied had been pasted, so removing it was the correct decision :slightly_smiling_face:

I was confused as to where it was pasting the information from, but then I realized that it is from Switch of Variable section.

This has given me an idea to re-work a section of a different macro that I have.
I’m assuming it is possible to do an if variable that if a checkbox is checked it pastes in one thing and if it is not checked it pastes in another or does not paste anything at all.

Yup, you got it. The key information being pasted was all being handled in the Switch of Variable action, so the additional "Insert Text by Pasting" action was just adding information that didn't need to be there.

And yes, it is absolutely possible to use an If Then Else or Switch action with a "checkbox" variable that pastes one thing if checked and does other things if not:


I added something to simulate hitting the space bar, escape and then the space bar again to get the keyboard navigation to work for the drop down menu and it doesn't seem to be doing anything.
I currently have it with pauses as you can see, but tried it without and with different length pauses and no difference.

The reason this isn't working as expected makes sense when you understand why, but is pretty unintuitive if you don't. Essentially, KM always waits for the current action to be completed before proceeding to the next action, which most of the time is exactly how you'd want it to behave. However, in this case, that means that it won't start pausing or typing keystrokes or anything else that comes after the prompt because as long as the prompt is active, the macro is effectively standing still. It's only when a selection is made and the prompt closed that the rest of the macro proceeds, but of course at that point, the rest of the steps designed to automatically drop down the menu are pointless. Fortunately, there is a workaround, though again, it's not immediately obvious.

The best way that I've found to resolve situations like this with native KM actions is to put the actions you don't want the macro to wait for in a different macro altogether, and then execute that macro asynchronously. In this case, this lets you call up the prompt but doesn't bring the rest of the macro to a standstill, and everything works as expected. As an example, in this version of the macro:

Popup Menu Test.kmmacros (7.4 KB)

The "Prompt for User Input" action has been replaced with an "Execute a Macro asynchronously" action. That action calls this macro, which is the exact same prompt action we were using before, only now it's in its own, separate macro:

Asynchronous Prompt.kmmacros (1.7 KB)

In practice, the two macros run identically to the way the macro was set up before, but by running the prompt asynchronously like this, the rest of the actions designed to drop down the menu for us are able to run when we need them to.

I have not been able to determine any reason or cause for the problem, so no, not currently. The behaviour of controls is entirely the system’s purview, so it is not something Keyboard Maestro is influencing per se. I don’t know why it fails in Keyboard Maestro’s windows, presumably something related to it being a background application. It has been there for many versions of Keyboard Maestro and many versions of OS X, but I have no idea why the normal system behaviour does not work properly in those windows.