List of all instance and local variables

I can get a list of all global variables using the For Each and then picking "The variables", but is there a way to get a list of all instance and local variables?
When we have an Execute Script actions and we click the arrow to show all variables, I can see all variables including local ones, so I would assume that this information is stored somewhere?
image

I tried this macro, but it seems to only include global variables, even if I remove the If Then action that seems to filter out instance and local variables.

Also, I notice that when I create a local variable, even if I then delete the action(s) using it and I delete the macro, when I go to that execute script menu, I can still see it on the list. I tried using %Delete%, but no luck.

Setting it:
image

I can see it on that list
image

Then set it to %Delete% and ran the macro to "delete" it
image

Delete the action and the macro, checked the list again (from another macro), still there.

EDIT: Ok it seems that restarting Keyboard Maestro is enough to make those go away. So I guess that the list on the Execute Script actions are local variables actually being used by the macros I have. I thought I had orphan variables there.

It can list all of them. I use it every day.

2 Likes

Thanks for sharing, Dan.
I downloaded it, but I gotta be honest: that gives me huge anxiety, because I have no idea what I'm looking at... There's too much information and not only that, a lot of it goes over my head, as my level of expertise is not on your level :confused:

So, if you don't mind explaining this to me:
1 - If I want to check all variables available (global, local, instance) used by all macros, not just one, which of your macros should I run?
2 - If I use this on a single macro, will I be able to rename a certain variable on all actions? Let's say I was using "local_time" and now I want to change it to "Local__myTime". Will any of your macros be able to make all of the changes in all actions using "local_time"? When running the Introduction macro I saw that there's a "rename" button, but again, this is too much information for me and I don't want to mess anything up.

Thank you!

I 100% understand that feeling!

Run the macro "25)Inspect All Global Variables & Dictionaries" to inspect all your Global variables.

If you want to see variables in a macro you're running, including Local and Instance variables, look at the macro "15)How To Use the Variable Inspector Prompt".

Copy the green group and place it in your macro. I actually have this as one of my "favorite" actions, so I can paste it into a macro whenever I need it.


As for renaming variables that you use in your macro, that's not something VIP is for, because that involves altering the macro itself. I'll post something about how I do it, tomorrow. But in the meantime, use the KM Editor's "Search" control (upper right), then change the variable names manually.

So it seems that 25) only shows all Global variables (similar to using For Each, The Variables, etc)?
And 15) only shows Local and Instance for the current macro?

Because I wanted to get the list of all variables (global, local, instance), for all macros in all macro groups. Similar to when you click the "arrow" next to the textarea in any Execute Script action and you get "Include All Variables", "Include no Variables", and then the list of all variables, you know?

One of the things I was trying was to select All Macros (smart group), exporting as a single file, then run a macro that performs some "cleaning" until I get the variables I want. Not a big deal, but if someone had another solution, I could save myself some time to avoid the "have you tried this...?" haha

For a long time now I started using my local variables as "Local__" but some older macros and some macros I downloaded form the forum, use "Local_" and so when I go to that list in the Execute Script, I end up with 2 local lists, which can be confusing, because they are not sorted (if that makes sense?). So I would like to slowly start updating all the "local_" and "Local_" to "Local__"

Remember that that is a list of all the variable names the Editor "knows" about. That's variable names used in all your macros, plus names you've recently used even after the only action referenceing that variable has then been deleted.

Why? And what do you mean by "available"? Because local and instance variables might be named in your macros, but they only "exist" in any usable way while the macros using them are executing.

2 Likes

That list is something KM keeps track of internally. I know where it's kept, but I wouldn't touch it with a 10-foot pole.

I'll make a separate post about this sometime today.

available where ?

The only variables that are generally "available" (in a global scope) are the global variables.

Application("Keyboard Maestro Engine")
.variables
.name()

Tighter (more local) scopes summon them into existence out of thin air at run-time,
picking local names, and binding local values to them.

After a fleeting moment of "availability" within such limited and temporary scopes,
they vanish back into total non-existence, and total non-availability.


The KM editor can derive a list of all the names that are seen in macro source,
but unless those names are globally bound they have no value.

A name without a value is not a "variable" – its just a string of characters)

(a "variable" is a name-value pair, and the sound of one hand clapping has never meant much)

3 Likes