Using ActionResult difficulties

Trying to have a keyboard shortcut toggle start recording a new macro and stop recording. I can't seem to evaluate ActionResult, though. Tried If/Then criteria both with calculation criterion (Actionmenu<>"OK") and now with the "The Variable" criterion. The calculation apparently always returned false and the "The Variable" criterion always returns true. What am I missing?

ActionResult is a text token, not a variable. It is also the result of the last action to complete, so it is very transient.

In the macro you show, the result of the menu selection should be shown briefly - that is used correctly. It will be OK if the action was a success, and a message otherwise.

However, after that action, the %ActionResult% text token will be OK because the Display Text Briefly action worked fine! So even if the If Then Else condition was correct, it would still not work. But the If Then Else condition is testing an ActionResult variable, which doesn't exists (well, it might exist, but its got nothing to do with what you are trying to accomplish). You need to use a Text condition.

This was super helpful. A bit of sample code in documentation would help future users :wink:

Thanks Peter that was the answer to what I have been trying to do for over a week now, and have spent hours on! I too would love to see more example macro’s and code. This seems like one of those things you could never intuitively figure out without seeing some examples. I am so happy this is working now and can see several places I can use this!

For whatever reason this doesn’t work for me. I’m trying to catch if the action tries to select a menu entry which is not enabled. %ActionResult% is always returning OK in such a case. If I enable “Failure aborts macro” and “Notify on failure” the macro shows a failure message. On the other hand %ActionResult% is not OK if the menu entry does not exist.

I’m using the latest version KM 7.3.1. Did something change maybe?

This is a reminder that these kind of problems cause many people to spend lots of time and effort re-inventing the wheel (ultimately requiring discussion on the forum!) to figure out what is a text token vs a variable…

Maybe these text tokens should be a special kind of variable, collected under some separate “KM special variables” group. Then they would be easily viewable, hint at user what fxns are available, and usable as variables (which is how people expect to use them, rather than having to create a “text” condition to assess a value!). If the result were desired as text, the nomenclature %Variable%VariableName% could still be used!

Hope this is helpful :slight_smile:

1 Like

I can confirm this behavior: Select Menu Action always returns a %ActionResult% of "OK" regardless of success or failure.

I think this is a bug. @peternlewis, can you confirm?

Here's a test macro which demos the issue:

###Example Results

###MACRO:   Select Menu Test Results

~~~ VER: 1.0    2017-07-19 ~~~

Select Menu Test Results.kmmacros (5.7 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


ISSUE: Select Menu Action always returns a %ActionResult% of "OK" regardless of success or failure.



  1. Select an Action in this Macro that is expanded (not collapsed)
  2. Visually confirm that the KM Menu View>Expand Action is disabled in the menu.
  3. Trigger this macro from the KM Editor App.
  4. Note that results displayed show an INCORRECT %ActionResult% of "OK" even though the menu item was disabled before the macro was triggered.


  1. First select an Action that IS collapsed
  2. Visually confirm that the KM Menu View>Expand Action is enabled in the menu.
  3. Trigger this macro from the KM Editor App.
  4. Note that results displayed show a %ActionResult% of "OK", which is CORRECT.

@Acky, as a workaround, I'd suggest that you test for the menu item being enabled before you try to enable it and do other actions.  For example:

<img src="/uploads/default/original/2X/1/161341587dc7c0124c8806b796dff9b3202a1929.png" width="465" height="456">

The behaviour happens because historically there was no ActionResult, and so the action basically does:

  • if we aren’t going to stop on an error, try to select the menu anyway, even if disabled, and report the error that that gives.

Unfortunately, the accessibility API apparently does not report any error if the menu is disabled. Before ActionResult, this made no difference since you couldn’t detect it anyway.

I will alter the code to report the menu as disabled and not attempt to select it if it is disabled for the next version.

1 Like

Great! And, I hope, you will return a ActionResult other than “OK”?

1 Like

@JMichaelTX: Thank you for digging into this. Your suggested workaround works fine and helps me :+1:

1 Like

Back on my ActionResult-should-be-a-variable soapbox:

I just made a button-based user input dialog, and since I’ve finally been trained to test for text strings (eg %ActionResult%) instead of variables, I was searching and searching for the name of the text string to give me the name of the button that was pressed.

Of course…it’s a variable!! :scream:

And when I go to look for the variable “Result Button” (which is counterintuitive because there’s a space :slight_smile: ), it’s buried among dozens of my own variable names!

I recommend having KM results (including ActionResult) be stored in variables, when possible, and that they be grouped in a submenu at the top of the “Variables” pick list



Why - variable names can have spaces in it. This isn’t the 1970s…

It is more likely that Result Button would beome a token than ActionResult would become a variable.

Sometimes I am constrained by the sequence in which I implement things, and if I was to release Keyboard Maestro for the first time today with no existing macros or user knowledge to worry about, it is very likely that ActionResult and Result Button would both be the same style, probably text tokens.

But life does not generally give you a clean white canvas to start from.

Peter, I'm not aware of any languages that allow Spaces in variable names. Could you give us an example or two?

Even though KM allows it, I don't use spaces because:

  • It is harder to select the text of a variable name. Without any spaces, a simple double-click does it.
    • For example, I find it irritating when I add a new Action that has %Variable%Variable Name% entered into it by default
    • If it has "Variable_Name" then I could easily select it and change to the real variable
  • Even though KM allows spaces, as soon as we want to use a KM variable in a Shell Script or JavaScript-in-Browser, we have to replace the spaces with underscores, adding to confusion and typos.
  • It is harder to read for me, but that could just be because of years of conditioning. :wink:

Just my 2¢ :wink:

How about simply adding "ButtonResult" (to be consistent with "ActionResult" in the next version? You can leave "Result Button" so existing macros won't be broke.

It would also be helpful to add "Button Selected on Last Prompt" to the "Macro Information List":

In visual languages? Sure:

  • Scratch variables
  • File names in the Finder
  • Contact names in Mail/Messages
  • Payee names in Banktivity
  • Etc.

In text programming languages, it is rare, since text processing languages use spaces for delineation. But Keyboard Maestro is not primarily a text language. The most obvious comparison is with the Scratch visual programming language, which has no trouble with spaces in variable names.

Yes, this is good idea.

Something like this is done for the next version.

But if they were variables,

  • people would already know how to use them without having to figure out the separate text token system: it’s MUCH more intuitive for a new person to click “if/then” -> “the variable:” than “if/then” -> “the text”!

  • they could still do everything a text token does, just with the format %Variable%foo% instead of %foo% (and thus you could still do an “if/then” using “the text:”)

  • they could all be listed in a submenu under the variable list, which not only makes them easy to find, but also gives the user ideas as s/he looks at the variable list to see the kinds of information Keyboard Maestro makes available!

In fact, a person with some programming experience could write an if/then statement using “Action Result” out of the box if it were a variable and in a submenu in the variable list, whereas currently one has to read the manual or visit the forum to hope to do something like that!

(And I had to do that repeatedly until I got very used to it!)

Are you familiar with the great macro by @DanThomas:
MACRO: [KMFAM] Favorite Actions and Macros

This allow you to store customized Actions, and then easily find and insert them into your macros.

I have a custom Action that deals with the ActionResult token:

and one for the Result Button

To get either of these, I just pressed the hotkey F12, and typed "if":
(I could also have typed "last" or "button". You assign the title when you store the Action, and it can also have keywords that are included in the search)

I use Dan's macro many times a day, and it makes my life simpler and less stressful. :smile:

Action Result has its own condition in 8.

1 Like