REARRANGE: Switch/Case & User Input Prompts

In response to a user request a while back, I came up with a solution for reordering the elements of Switch/Case groups and Prompt For User Input actions.

I overhauled the original macro today, so I thought I should probably create its own forum post.

Usage:

Select either a Switch/Case group or a User Input Prompt action and trigger the macro.

Depending on what was selected, one of two prompts will appear:

As you can see, nested Switch/Case groups are supported.

You can now drag-and-drop elements up and down within the prompt and click OK to submit it. The selected action in your macro will be replaced with your newly rearranged version. If you change your mind, just use KM's Undo feature (⌘Z).

Macro Download:

Reorder Switch-Case or User Prompt.kmmacros (115 KB)

Macro screenshot

10 Likes

Great!

Can I change the font size for ā€˜case-value’ in the ā€˜Custom Prompt’ without causing any unwanted side effects? I’d like to display more entries. The same question applies to ā€˜max-height’ in ā€˜case-list-wrap’. (Long lists look better on my 24-inch screen at 1200 px.)

No probs. I've updated it above to allow you to set a few preferences related to font/height.

1 Like

Very helpful! Thank you.

A slightly cheeky question:

Would it be possible to sort the entries automatically, e.g. alphabetically (I’m aware of the risks)?

Or to use a list?

For example: If the current entries are

  • abc
  • xyz
  • efg
  • bcd
  • most frequently used

and I’d like them to be sorted as in this list:

  • most frequently used
  • abc
  • bcd
  • efg
  • xyz

Hello Neil (@noisneil) :waving_hand:

You did it again … a superb job. Have you thought about making it supporting IF Actions and all other Actions which work with conditions, too ?

If you could do this it would be great. Yes it might be a lot of more work as there are much more conditions to work with… but highly appreciated.

Again, thank you very much for such a great Macro.

Greetings from Germany :germany:

Tobias

1 Like

Good suggestion! I've updated it above.

CleanShot 2026-06-28 at 07.38.55

If/Else only has two possible states, and while I can imagine reorganising a complex series of nested If/Else actions, I don't think it would be any quicker in a prompt than in the KM Editor's own interface.

I specifically targeted Prompt for User Input and Switch/Case, as you can end up with dozens of entries that are laborious to rearrange manually. If there are other examples you can think of that pose the same challenge, I can try to add them.

Great work, @noisneil! :clap: Thanks for sharing this gem.

I suspect @Nr.5-need_input is requesting a method to reorder the conditions (when there are two or more).

Oh I see. Yes, that could be done, but is it often called for?

In my personal experience, I don’t think I’ve ever needed to.

Not often, but I've occasionally rearranged:

  • any conditions placing the condition most likely to be true at the top.
  • all conditions placing the condition most likely to be false at the top.

With this, I suspect @Nr.5-need_input is referring to Until, While, Pause Until, etc.

The cases I’ve dealt with truly are time sponges, whereas rearranging conditions seems somewhat luxurious, so I’m less inclined to further complicate things by parsing a laundry list of action XML.

1 Like

Guilty as charged! Yes, perfectionism can often be a curse. :zany_face:

1 Like

Hello Guys

Many thanks Jim (@_jims) for clarification on my recent post. Appreciate this.

Neil (@noisneil), even though I’m a little sad that you wouldn’t integrate my requested features, I think I understand your concern. Irs indeed a lot of functionality to add.

I wish I could help you out on that - so so youā€˜d have some less work to do it. But unfortunately I’m extremely busy at the moment.

Perhaps in the near future? (Just asking because it costs nothing than words).

Greetings from Germany :germany:

Tobias

It might help readability, but does it have any difference come execution? I seem to remember @peternlewis saying that all conditions were evaluated simultaneously and that there was no short-circuiting.

Ah, found it (or rather another reference to the same, since this was before my time):

So it seems to be a lot of work for little actual return.

3 Likes

With the way my brain works, it helps me think through the logic better if I place them in the order I mentioned above. This might also go back to my time writing C; in those days short circuit evaluation was important.

I think it’s safe to say that I’m in the minority. :zany_face:

2 Likes

Then we're in a minority of two -- I think the same, do the same, and even used to recommend it for efficiency in KM until Peter put me straight about the lack of short-circuiting.

1 Like

Most of us who had programmed using switch/case statements before using them in KM would probably add a lot to the total.

My bet would be that KM evaluates the conditions fast enough that the chosen style of testing conditions should be imperceptible in most circumstances. Even so, finding out about this encourages me to bear in mind always how switch/case conditions might be combined in order to make the list of conditions as short as possible.

1 Like

It's the speed of the Condition-determining test(s) that matters. An "all must be true" will complete evaluation when the slowest test completes, an "any" will complete when the fastest is done (the macro moving on to the next block while the other tests complete in the background).

You know I love a demo...

All vs Any Timing.kmmacros (7.9 KB)

Result:

The 5 second delay in the AS is just to make things obvious -- even without that the "any" will complete faster:

...because of AS instantiation time.

If you want to optimise, look to the construction of the logic (perhaps at the expense of readability). So this:

...should be replaced with:

...if the calculation part will return false even only 10% of the time.

2 Likes

Yes, that’s why I didn’t bother testing it myself!

2 Likes