Determining the Variables Used by a KM Macro

Continuing the discussion from PHP Action Plugin:

@peternlewis, well I read and reread the Halting Problem article, and I don't see any relevance to determining which variables a KM Macro needs.

Clearly this can be done, because many compilers do this.

In fact, even KM does this. It extracts every variable from a Macro and adds it to the variable database and list that is presented to select a variable by name.

We must be referring to different things, to be so far apart in our understanding.

So, without referring to the Halting Program, what am I missing?

The Halting Problem is about the fact that it is impossible tell for every given problem whether the program will execute to completion or run forever. More generally, you cannot know which parts of the program will necessarily be executed or not.

Along these lines, there is no way to determine what parts of macros are executed in general. Given that you can do things like reference variables based on the values of variables, execute macros based on the value of variables, there is no way to know what variables a macro will use, or similarly, what variables are used by a scripting language.

Keyboard Maestro lists all the variables it knows about, but you can use variables it does not know about in a macro. And if it gets it wrong, all that happens is it is not listed. There is no broken guarantee, as there would be in this case if the action claimed to only provide variables that are used by the macro and/or script.

1 Like

So, then include all variables that are referenced in any way in the Macro, just like you do when collecting variable to add to the KM Variable database and list.

With all due respect, I think you are over-thinking the problem and making it be much harder than it actually is.

Again, I don't think this is an issue.

At the point when an Execute Shell Script, or Execute Javascript, is called, KM knows about all of the variables that have been created by other scripts (like AppleScript). So you could just add those to the collection used directly in the macro and Shell Script.

I do, I include all the variables, which includes all the variables used by the macro, that will fit within the environment variable space.

I'm not overthinking it at all - I'm including all the variables, there is no thinking required.

If you want to pass large chunk of data (more than a dozen k), perhaps just don't use an environment variable to do it.

You just said that you could NOT determine all of the variables used in a Macro. So which is it?

I include all the variables, which is necessarily a superset of all the variables used by the macro.

I cannot determine which variables a macro accesses with sufficient accuracy to make it a sensible option to add to the action.