What's The Purpose Of The AccessedVariables Token? (KM10)

@peternlewis Regarding the new %AccessedVariables% token, I believe that:

  • When a macro is executed and the token is encountered, the token returns a list of variables that were accessed while the macro was running, up to the point the token is used.
  • If a variable is in the macro, but it hasn't been used yet, it won't be returned in the list.

Does that sound about right? If so, what's the purpose of the token? What might I use it for?


Hmm… if your understanding is correct, that would be useful to ensure all variables are cleaned up at the end of the macro if you’re not using local or instance variables. You could maybe use that token to create a list of variables that can then be deleted or emptied.

Sometimes I use global variables while building a macro and want to make sure they’re deleted at the end of the macro (usually I convert them to locals once the macro is stable), but it can be easy to miss one or two, especially on larger macros.

But only if they're accessed by the macro during that run. Depending on various conditions, it might not cover all variables in the macro.

Very true.... :thinking:

I'm sure there's a fair amount of uses for it. I did just use it to check one of my more complex macros to see what variables it accessed and discovered two long-forgotten variables that are still in the macro that are no longer needed. So it at least let me delete those two haha.


Could you please show us how you used it, just so that I don’t t have to reinvent the wheel. Totally fine if you think it’s more effort than me just looking it up myself.

Just put this at the end of a macro:


In addition to Dan's method, I created a simple subroutine that I can place at the end of any macros I want to "audit". You would need to create a txt file and place it on your desktop (or wherever you want it, and update the filepath) for it to write to. This way I can just add it to my macros and then review them later when I have time by reading the text file.

16)Variables Audit.kmmacros (1.9 KB)

1 Like

It simply exposes the list of variables that are displayed in the Debugger (space permitting).