"IF/THEN/ELSE" Action Not Working With a TriggerValue Variable

Goal

A self-contained "inner" macro that checks whether a value has been passed in from an "outer" macro. If no value is found, set a variable (%Local_NUM_TO_CLOSE% in the example below) to a default value. %TriggerValue% seems like the way to do this, but I can't seem to get it to matter to the If All Conditions Met action.

Demo Macros

Here's a Short, Self Contained, Compilable Example demonstrating the issue I've encountered.

Download ⇢ Notifications Macros.kmmacros (4.5 KB)

Contains 2 macros. The "outer" macro just calls the inner one, setting a value in %TriggerValue%:

Outer Macro

The "inner" macro checks %TriggerValue% and forks the flow accordingly.

Inner Macro

The Problem

When I run Inner, the results are as expected…

…but when I run the Outer macro, the condition, TriggerValue is > 0 still fails, even though the test value, 8 is definitely > 0:

It's worth noting here that I first started with a simpler condition: If %TriggerValue% is empty, but that suffered the same issue. The failure branch seems to get triggered no matter what condition I use against %TriggerValue%.

Question

  • Am I doing something "wrong" here, or have I encountered a bug/limitation in Keyboard Maestro?

Hey Chris,

You were trying to use TriggerValue as a variable without ever having assigned it.

Note how I've changed your IF condition to use a text condition and the actual trigger-value token:

image

It's better not to use variable names too similar to token or function names, so you can tell at a glance which is which.

It's also better to use display text in a window actions when testing (in my opinion) – they are more flexible and are persistent.

-Chris

2 Likes

As @ccstone notes, TriggerValue is a token, not a Variables.

Huh.

Well, feature request, I guess: this sort of thing would be more discoverable if the field either had some sort of warning ("This is also the name of a Token…you sure you meant to do this?")… or, better yet, add Token support so that the original thing I tried to do doesn't fail so mysteriously. ¯\_(ツ)_/¯

Maybe this…

…or (slightly less friendly, but perhaps easier to implement) a token-specifc option, like this…


Suggestions aside, thank you! for the quick feedback. Spot on as usual, @ccstone. :blush:

1 Like

This is kind of one of those RTFM moments I'm afraid...  :sunglasses:


Keyboard Maestro has two very distinct types of fields: text fields and numeric fields.

  • Most text fields allow the use of tokens.
  • Most numeric fields allow the use of Functions.

** Keyboard Maestro Wiki ⇢ Text & Numeric Fields


The different types of fields in KM are:

  • Numeric Fields
  • Text fields
  • Script fields
  • Variable Fields

Peter made this more discoverable by employing field labels, but they are only visible with the text cursor is in the field (none in script fields):

image

image

image

image

It makes no sense to describe a text token without using text-token-syntax %TextTokenName%, as they can only be used in text fields and must be distinctly not normal text.

1 Like