Custom HTML Prompts :: Variable Value at Launch Time vs Value Now

If you need to detect variable value changes from inside a Custom HTML prompt action, it may be useful to notice that in addition to:

window.KeyboardMaestro.GetVariable( 'KMVariableName' )

(which yields an up-to-date copy of the Variable value, at the the time of code evaluation)

you additionally have access, through document.kmvar, to a frozen snapshot of the Variable values, as they were at the moment that the Custom HTML Prompt first launched

This means that you can detect changes by comparing the two results:

  • document.kmvar (values at launch)
  • window.KeyboardMaestro.GetVariable (values now)

For example this yields the following divergence of values, over time, for a KM Variable called localTemp:


Value timing in HTML prompts.kmmacros (2.0 KB)


This is really cool. You probably already know this, but here's another cool thing about document.kmvar:

If I run a prompt asynchronously and try to use window.KeyboardMaestro.GetVariable() to get the value of a local variable, it quite reasonably returns an empty string.

BUT, the local variables are in kmvar.

So if I want to pass some starting parameters to an async prompt, I can still do it. Very cool.

Thanks for sharing this.