Get KM Variable into Javascript Action

Apologies, I've been here before and believe I was supplied with a solution, although I cannot find it in my database or on the forum.

Is there a way to call a KM variable into the javascript action?
So that instead of the subject being the 'hard coded' "MY TEST" , it could be the value of a KM Variable that I have stored?

Get KM Variable into Javascript

Execute a JavaScript in Safari.kmactions (733 B)

For JavaScript executed in browser contexts, Keyboard Maestro provides (read-only) access to variable names and their values by initialising a document.kmvar object.

You can read its keys and values in the usual way, but you can't change KMVAR values through it.

If I have, for example a KM variable named 'scratchpad':

image

(For JS executed in a JavaScript for Automation context, there are both kmEngine.getvariable and kmEngine.setvariable methods, but these are not, of course, available in browsers)

For a panoptic view of the contents of document.kmvar, you could also, of course, write:

image

2 Likes

I can't comment on what's going on in the webpage itself, but if I assign a value to a name like text (beware of name clashes, of course :slight_smile: )

then the KM action has no difficulty in finding it here:

image

I presume that you are seeing the value if you do this (with the action displaying its results in a window) ?

(ah ... looks like you've you fixed it – good luck !)

1 Like

Yes, ahum...

The name text for a 'testing' variable would not be a good idea. I used another variable and worked perfectly.

NOW – if only the body in Gmail had a 'name' as the subject field does, I'd be good.

For whatever reason the Xpath id cannot be used because it is always different each time I compose a new email...

Another topic I suppose.

Thank you for your time and expertise, much appreciated.