How can I access KM variables inside a Script Condition?

Hello, community.

I would like to access KM variables inside a Script Condition. I created a minimal working example. In my test, I am using JavaScript For Automation script. I am setting localText to 1, but the alert shows "Is not 1". Is there something wrong in the macro ?

Download Macro(s): Accesing KM variables inside a Script Condition.kmmacros (3.2 KB)

Macro-Image

Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
System Information
  • macOS 14.7.2
  • Keyboard Maestro v11.0.3

The problem is you're not using "Modern Syntax" for your JavaScript and you're not allowing any KM variables into the scope of the script.

The change you need to make is simple: just click the down-arrow to the left of the script text box and check these two items as shown here:

image

That should do the trick!

Thank you, @tiffle. I have been using Modern Syntax in Execute a JavaScript For Automation action, but I hadn't seen that down-arrow to the left of the script box.

1 Like