Choose from list of options?

Hi, this is my first post here. Also this is one of my first days using Keyboard Maestro, so please forgive me if I fail to understand the basics.
Another thing is that I am blind, please try not posting screenshots when answering me, as this will be difficult for me to comprehend.

I am building a macro that will open an URL from the clipboard (screenshot below). I know that the regex itself needs a little bit of ironing out, but thats irrelevant now. I have two problems with this macro.

  1. The "Else" statement is never executed.
  2. How can I make it that if there's only one match, just open the URL. If multiple matches are found, just show me a list of URLs in a list, so that when I select one it will open the selected one?
    Here's my macro, sorry if the screenshot is bad, I just took a window screenshot.

Welcome to the forum, we'll do our best to help you out.

Without seeing the entire macro, it's tough to say exactly what wrong, but my suspicion is that it's your MMurl variable: That's a global variable, whose value persists forever. So once you set it, unless you add an action to delete it, it will always have a value, so your else condition won't ever occur.

Again, hard to say without seeing the full macro, but you could probably use a local variable or an instance variable instead, as those both clear after each run of the macro. Change MMurl to local_MMurl (or whatever you want after the "local" bit), and the value will always be empty when the macro starts—I assume you're setting its value earlier in the macro?

You can post the full macro using the Share icon in the toolbar at the top of the editor window. Click that, then select Keyboard Maestro Forum. Click New Topic, and the macro will be shared—you can buy and paste it from the new topic back here to paste in an existing topic.


I have tried doing that but I cannot seem to find my topic to post a link to it, eh, let's try this method instead. I am sorry for all the confusion I am causing xD..
Otwórz adresy ze schowka.kmmacros (3.9 KB)

It never gets there -- your "Search" action is set to its default, which is "Abort macro on failure". So when there's no match your macro exits rather than going on to the "If" action.

You'll get a notification of this unless you've turned off KM's notifications in System Settings (notification on abort is also that action's default setting).

You can change the action's settings via its "Options" menu (the cogwheel in the top-right corner). Uncheck "Failure aborts macro" and it'll work as you want.

A bigger problem is that the "Search" action only ever finds the first match -- you'll need to use a "For Each" to return multiples that you can pick from. This is detailed on the action's Wiki page, with links to "For Each" and an example of use.

Have a go using "For Each" instead, but don't waste too much time if you get stuck -- shout for help and I'm sure people here will jump to the challenge!

I have managed to almost get it to work but I have some problems.

  • Is there a way to not show the search field, just the plain list without anything else?
  • Can I make it that the variable is empty when I press ESC in the list?
    Here is the fixed macro. Thanks guys, you are very helpful.
    Otwórz adresy ze schowka.kmmacros (5.6 KB)

If you're using Prompt With List, the search box will always show. Two ways around it that I can think of would be:

  1. Use Prompt for User Input with a pop-up menu of the variable's values. This will put a modal dialog onscreen and require a mouse click (or tab and enter) to show the list, though.

  2. Write a Custom HTML Prompt to display the variables in the list, and use Javascript to process keypresses to select and activate entries in the list.

Option one gets rid of the search box easily, but replaces it with probably a more cumbersome interface to navigate. Option two gives you full control, but is much tougher to implement, unless you're quite comfortable with HTML, CSS, and Javascript.


If I go with Option 2, will it be rendered as a web wiev or there's some magic which maps html elements to standard cocoa ones?

It's a web view. Open the Macro Library (Window > Macro Library), and select the Custom HTML Prompt Example. Run it, and it generates a web form. This isn't perfect for your needs, as it doesn't do any Javascript processing, it's just a straight form. But it shows how it works.


Ahh, then its a trouble since I cannot quickly choose an address with arrow keys. I have to find a better way. Can I atleast make it that the list gets keyboaard focus and not the search field?

Use "Prompt for User Input" rather than "Prompt with List".

You can check the button pressed, and blank the variable if it was cancelled (otherwise it'll have the value of the default choice).

Have a look at this:

Otwórz adresy ze schowka copy v2.kmmacros (7.2 KB)


If you want to avoid using the mouse to select something (and haven't turned on the OS Accessibility options) you could use "Prompt with List" -- arrow keys should let you change selection, Return to select, Esc (maybe twice) to cancel.

That's what I was saying about Javascript processing: You can make the arrow keys work, but it will take added code. (And I am not the right one to do that kind of stuff, as Javascript is definitely not my strong suit. But I've mucked some stuff together over the years using the advice of others here and some web searching.)

As an example, my The Decision Maker macro uses a custom HMTL prompt and key processing to react to key presses in the web view.

I imagine someone much better than I at Javascript could explain how to code support for moving and selecting with the arrow keys in an HTML prompt.

The list portion of the box never gets focus; it's always on the search box. However, the arrow keys (up and down) and the Enter key should work anyway—they do in my testing here.