Adding a dropdown (or choices) to a macro

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:

Yeah.
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:

Thanks.

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.

I tried the Set variable option from KM8 that you gave me the example of and that works great except I'm not getting the results pasted into Chrome.

Thanks again for the help.

No problem, Steve! Is the screenshot you just posted the full macro? If so, there doesn’t seem to be an “Activate Chrome” action in it, so that could possibly explain why it isn’t pasting into Chrome. If that doesn’t seem to be the answer, try posting the full macro and that should give us a better idea of what’s going awry.

I also noticed that you changed the mouse action from a simple double click to a double click and drag. Can I ask what the purpose of the mouse action here is? If it’s to select the Chrome address bar for the purpose of searching Google, I can suggest much more reliable methods of doing that, such as having KM type ⌘L instead of clicking the mouse, or even reworking your macro more substantially to automatically open a Google search URL in Chrome with the selected option without any clicking or keystrokes.

Attached is the full macro.
Chrome is already active when I start the macro, because that is where the "copy" in the beginning is happening.
The reason for the drag is because I am replacing a portion of the URL in the Google address bar, so it starts at the beginning of the word and drags to the end.
The length of the word being replaced varies and sometimes has dashes in it so a double click will just highlight and replace the first portion, up to the dash.

Prompt for User Input.kmactions (0.8 KB)

Thanks, Steve! I think I see what the problem is now. The Switch/Case action you're currently using is set to look for exact text in DAT__Search for:

This worked with Prompt for User Input, but since you're now using Prompt With List, which includes numbered prefixes to ensure the right order, what you now want is Contains:

While this should get the macro working as expected again, I think you would still be better served by avoiding the mouse actions altogether, assembling the entire URL in either the clipboard or a variable, then posting the results in Chrome's address bar (or, alternatively, opening a new Chrome tab with the assembled URL, which would simplify the macro even more). Here's what that approach would look like using the clipboard (new actions have been colored orange and yellow):

Popup Menu Test 1.2.kmmacros (15.2 KB)

This approach would also have the added benefit of making it much easier to add new options to the prompt, since each new option would no longer need a new Switch/Case branch but could just be added to the Set Variable to Text action at the beginning of the macro. Hopefully this all makes sense; as always, feel free to ask more questions if it doesn't!

Yeah, That did it.
I should have caught that.
I actually left it as is and added the numbers to the choices.
So 1) Clipboard, 2) Option 2, 3) Option 3.
I did this because contains leaves room for an error of something that you don’t want.

I’ll look over your suggestions and see if they will work.

1 Like