Get & Set ( Update ) KM Variable in JS

First of all, it might be an easy one. if it is, plz forgive my poor knowledge. :frowning:

Created 2 functions. But it's not working well.

  1. Checking if the new id is contained in KM variable.

  2. Append the new id into KM variable.

I get this error.

Uncaught TypeError: Cannot read properties of undefined (reading 'eb_done_items')

What I missed?

Thank you in advance!

You can read and update KM variable values in the JavaScript context of an Execute a JavaScript for Automation action,

but in JavaScript interpreters embedded in browsers (Chrome, Safari) we can only read KM variable values. We can't change them.

See for example:

actions:Execute a JavaScript in Browser [Keyboard Maestro Wiki]

where it is put like this:


Using Keyboard Maestro Variables

JavaScript in browsers can only GET Keyboard Maestro variables. They cannot be set.


What you can do, however, is return a value, from a JS function, to a Keyboard Maestro action. See, on the same wiki page, the section lower down entitled:

Saving Results to Keyboard Maestro Variables

1 Like

How stupid I was...

I spent 1, 2 hours to find the problem. :cry:

I found that the spelling was wrong... ( kmvvar ==> kmvar ) :cry:

Sorry to bother you and thanks for your time :slight_smile:

A perennial problem for programmers I'm afraid.  :sunglasses:

-Chris

2 Likes

I forgot to mention...

It's best to never write or edit code directly in Keyboard Maestro.

Write it in a good programming editor like BBEdit or Visual Studio Code

You get nifty tools like code-completion and multiple cursors for refactoring variable names, etcetera.

Another thing that can help is to change the font Keyboard Maestro uses in its code actions.

See the Wiki on Preferences:

manual:Preferences [Keyboard Maestro Wiki]

Search for β€œfont”.

-Chris

1 Like