Prompting for user input with a list - can list item be preselected?

I am using a Prompt for User Input that has a list of names in:

...|Adam|Brian|Carolina|Dave etc

When the selection is made it stores that selection in a variable.

However, I would like the value that has previously been stored to automatically select the name. So if I chose "Brian" last time, when prompted again, that's the one I'd like selected when picking again.

Is there a way to do this?

Currently, I am having to make the selection from the list each time.

Yes there is.

You say that the first time, a variable is used to store the selection. Well, suppose the variable is called LastSelection just for the sake of explanation.

In that case, construct the list of choices in your Prompt's action like this:

%Variable%LastSelection%|Adam|Brian|Carolina|Dave

The first time through, LastSelection won't have a value so your normal list will be used but on the second and subsequent passes through, the default value contained in LastSelection will be offered too.

Note, the variable you use must be a global one if you intend for the default to be available from one run of your macro to the next.

I'm not at my Mac so I can't show actual KM actions as an example, but I hope you get the idea.

2 Likes

@tiffle explained it well. If you want to see another example I made this reply on another thread that includes a screenshot.

OK, cool. So rather than indicate further down the pipe separated list which one is selected, you are really duplicating by providing one at the beginning which will match one further down. But that still works for me :slight_smile:

It may or may not match what is further down the line, it will only show what is currently stored in that variable (which usually would be set by that prompt but not always). So you would still want to make sure to provide any options you may need in that same list.

Hi @Lloydi - yes, and that’s exactly how the Menu Field is documented in the KM manual page here: action:Prompt for User Input [Keyboard Maestro Wiki]

Hi @Lloydi. Over the last several months I've created many macros with dialog boxes. In those macros I've used a global variable to save each of the relevant dialog parameters and applied default values using the Prompt For User Input methods described above by @tiffle and @cdthomer.

This approach has worked quite nicely, but the downside has been that the global variable list (seen using the KM preferences) gets cluttered with these relatively trivial values.

So coincidental to your post today, I was working through a method to save all of the dialog settings to a single KM dictionary. Since this was my first application of a KM dictionary, I had to experiment a bit, but ultimately I like how it worked out and plan to use this approach moving forward.

I've posted an example macro which includes this dictionary method and some other dialog box techniques that I've learned previously. Here's the link::

4 Likes

I have not tinkered with dictionaries at all, so I will have to give this a proper read when my brain is in the right place for it :slight_smile: Thanks

1 Like