%AccessedVariables% token

This wiki page:

https://wiki.keyboardmaestro.com/token/AccessedVariables

says " The %AccessedVariables% token returns (v10.0+) a comma-separated list of variables accessed by this macro" when actually it seems to provide only a list of variables that have been accessed by the macro up until this token is evaluated. For example, this displays two variables names:

But this displays nothing (just moving the order around):

So the token seems to prove the names of variables that have been access up to that point in time, which isn't stated in the documentation. I just think that this should be clarified in the document.

This impacts a macro I was working on. Up until now I thought the token had pre-determined the names of the variables. Now it seems to be a dynamically collected list. I found a post where this token is discussed, and one user (Ph.Dan) implies that the token only works at the end of a macro. So apparently some people know about this detail.

This could potentially be clarified yes. For a native English speaker it makes a lot of sense already though. I don’t know how or if it translates to other languages / ways of thinking.

If it's obvious, then is it read access or write access or both?

Pretty sure the token only gives READ access to the variables that have already been accessed.

That's not what I meant. What I meant was does the %AccessedVariables% get populated by actions that read or write to KM variables. In my example above, it was populated by writing. Do you think it would also get populated by reading variables? The wiki page doesn't say. If it's obvious, what do you think?

It's any variable accessed (read, written) by the macro, up to that point. It does not pre-determine what the macro might access, only what it has actually accessed.

Note that if you run a Custom HTML Prompt in your macro, then after the prompt has finished (actually after it has started, but that's a moot point), %AccessedVariables% will contain the names of ALL your variables, because Keyboard Maestro accessed them all to fill document.kmvar in the prompt. No, Peter will not change this. Unless he changes his mind.

That's enlightening. Thanks.

When you said "ALL your variables" I guess that must mean all existing global variables (that's a lot) and it probably also means any local or instance variables that have been created, but it probably excludes all dictionary variables/keys.

I'm working on a really amazing macro. I'll probably end up needing your help because it uses Custom HTML Prompts extensively. And you're the Ph.D. at that. My macro wants to know what variables are used in the macro that called it. That's a bit tricky. But I'll manage by putting the onus on the programmer.

If what you want to know is what variables were accessed, then you're good, although the Variable Inspector Prompt does this.

If you want to know all variables that the macro contains, regardless of whether they've been used or not, give up now. Trust me on this. It's way more complex than you could possibly imagine, even if you think you can rely on the variables having a specific naming pattern. If you need more information, let me know.

I can be happy with giving the user the responsibility to "register" the variables that they want to use.

Yesterday I got my first prototype working, (it was exciting and amazing) and that's when I decided to go to sleep. I'm not sure at what point I will upload this prototype. It has many little problems right now. I'm going to try to fix some of those problems before I upload my first "beta."

1 Like