Select One of Three Actions at Random

I can't seem to find the answer in the forum.

I need my macro to choose one of three actions at random, but I am stuck as RAND (1,3) is red.


: )


Do you really have a variable named "RAND(1,3)"? :wink:

Use "If calculation RAND(1,3) is =..." instead.


As @Nige_S says, use the Calculation RAND(1,3), and the switch members should use the is = values.


1 Like

I'm sorry I am so remedial.

How do I get the action "Switch of Calculation" ?

  • Use the menu item Edit > Insert Action > by Name...
  • Type “switch”.
  • Insert the action.
  • Change the IF option at the top.

Don't forget that you can search the available actions, function, and text-tokens using the various Edit > Insert... menu items.

You can use the search field in the Help menu of the Keyboard Maestro Editor.

And you can search the KM Wiki.


Don't be! We've all done this at least once -- or, in my case, at least once a day...

Keep an eye out for red entries in KM's fields -- they mean it's an invalid entry. It might be text where a number is required or vice versa -- or, in this case "That can't possibly be a KM variable because the name is invalid" (variable names can't include a function name with spaces around it).

KM is "helpfully unhelpful" in that actions in macros are often renamed according to the options selected in that action -- great in that you can quickly see what an action does, not so great when you want to find the corresponding "basic" action in the Action List. As @ccstone says, "Search" is your friend and trying the first "programy" word in the name will normal find what you need.

1 Like

Still confused. Wen I add 'Switch/case' I only see these options, Searching for 'calculation' also didn't present the option I am looking for.

"Calculation" was added as an option in version 10 -- always worth mentioning if you aren't using the current version of an app.

If you aren't going to update KM, try splitting this into two operations -- set the variable to a random number, test the variable in the "Switch/Case" action:

You can do it all in one action by using a %Calculate% token to generate the random number in the Switch's "Text", but it will be less obvious what you've done when you look at it in a year's time!


1 Like

I upgraded to KM 10

I'm all set now. I didn't realize there was a new version.

This is just the best app in the world. Thanks All!