Bug in %AccessedVariables%? Or if this is WAD, it's unexpected

@peternlewis After executing a "Custom HTML Prompt", %AccessedVariables% returns what is probably a list of ALL variables.

I'm guessing that the process of launching a Custom HTML Prompt accesses all variables, so they're available to window.KeyboardMaestro.GetVariable(). If that's true, then I suppose it's technically true that all variables have been accessed, but it's certainly not what I would expect.

Any thoughts? Is this WAD, or might you change it in the future?

Thanks.

It could be that, but more immediately, Custom HTML Prompt, like the Execute JavaScript in Browser actions, also decorates the document object with a kmvar property, which does entail reading every variable to assemble a JSON representation which is passed in at the head of the file.

My impression of window.KeyboardMaestro.GetVariable() is that it accesses values in real time, so that (I haven't tested this), it's possible that the .GetVariable method and the kmvar property could return different values for the same variable name:

  • document.kmvar certainly contains only values as they were at the moment of launching the action.
  • .GetVariable may, I think, have real-time access to the value at a later point in time, when JS code evaluation (or other macros running in parallel) may have written updated values to one or more variable names. (The existence of .SetVariable() suggests this picture to me).

Off-topic, I fear, but it would be helpful to have a clear picture of all this. It could be useful if .GetVariable() access is indeed later than that of the kmvar blanket pre-read.

A quick test seems to confirm that picture:

1 Like

I'm not sure if all that is relevant or not - I could be wrong.

But consider this:

image

zzTest.kmmacros (2.6 KB)

The first Prompt for User Input shows no values for %AccessedVariables%.

The Custom HTML Prompt doesn't access the variables at all.

The second Prompt for User Input contains a list of variable names that scrolls off the screen (I need to do some serious cleanup). Fortunately, "Esc" closes the prompt.

The launch of Custom HTML Prompt involves the preparation of document.kmvar, which (behind the scenes) entails reading every variable.

Whether the mechanism that Peter is using (to track variable changes) allows for a distinction between an action reading the variables automatically, and a user accessing them explicitly, I have no idea ...

Hence, why I asked the question to begin with.

1 Like

Same picture with the Execute in Browser actions, incidentally. The second window here lists all variable names.

(a document.kmvar effect, rather than a .GetVariable() effect)

1 Like

No, it should not include all the variables.

It, like shell scripts, reads all the variables for the kmvar, but those accesses are implicit and should not be recorded for this purpose (reading the kmvar variables or the environment variables also, obviously, does not get included in this token).

It will be fixed for the next version.

3 Likes