Warning for “Execute Javascript” action with modern syntax using `document.kmvar.variable`?

I was surprised to find that the modern JS syntax uses kmvar.variable instead of document.kmvar.variable. It would be nice if when using modern JS syntax, document.kmvar would be flagged with a warning and an explanation of how to change it (similar to how unused loop variables are marked with a warning sign). A simple string search for document.kmvar should suffice (I doubt anyone is assigning document to a differently-named variable before use).

1 Like

Brevity and convenience apart, the cost adding Keyboard Maestro variable name keys to the browser document object is, of course, that the document object persists in a global namespace, and can be read by other scripts, which you may not want.


When Modern syntax is selected (small chevron menu to the left of the JavaScript text field), a special kmvar object is created in a temporary local namespace, which is not visible to other scripts, and evaporates when the script action concludes.

(Briefer, and more secure)

(You can also choose, from the chevron menu, which, if any, of your Keyboard Maestro variable names and values are added to that kmvar object)

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


It sounds as if you are asking for a pre-processor to run before script execution – I guess that might fractionally delay execution in Execute text script mode.

( Whether it would be feasible at all in Execute script file mode, I'm not quite sure. Sounds like a decompile -> preprocess -> recompile chain, which might remove any performance advantage from that mode )

1 Like

Noted.

1 Like

Done for the next version.

4 Likes