Many new variables after macro import

Sometime in the past few days I imported a macro (or library) from the forum in order to look at it. I suddenly have dozens of variables I never defined. Why would that happen? Do I have to worry about this every time I import a macro (or library)?

I found it to be very helpful to use a macro-specific “namespace” for variables, especially for bigger macros. For example essPath or ESS__Path, where the prefix hints at the macro name.

This makes it easy to clean up the variables when you no longer use the macro — and also for other users who just download and try the macro.

[Edit: Added screenshot:]

The inverse effect of this is that you also can easily spot unprefixed, “messy” variables, introduced with one-time test runs of third-party macros.

Hey Mitchell,

But you did define them when you imported a macro.

The variable pane displays all in-use variables in all macros.


The answer is yes.

Good macro design will include deletion of the variables it uses at the bottom of the macro, if they are no longer needed.

I just posted a macro to help you do this:

MACRO: [KM] DELETE List of KM Variables [SUB-MACRO]

OK, that macro is very useful, and the comments have been illuminating, but this is a real problem for users who want to try other people’s macros. Without any warning they get a few — or a swarm — of variables they never heard of. Even if the macros are subsequently deleted the variables remain. (A variation of DELETE List of KM Variables that would delete any variable not currently in use by some macro would be highly beneficial.)

I suppose that truly macro good design would create variables as needed and delete them at the end of the macro. Very few people posting macro would do that, though.

And this doesn’t always make sense. I have quite a few macros that store the last used settings (e.g. for the user prompt) in variables. So, deleting them at the end would reset everything each time.

Ah, of course. Silly of me. I do the same.

While we’re on the subject, can we get a list of the names of the variables in a fresh installation of KM?

@MitchellModel I added a screenshot to my comment above to illustrate the effect of neatly prefixed variables.

Tom, I use the same approach and it works well.

Also, since you didn't mention it, it appears that you are using two underscores at the end of your prefix. A big benefit of doing this is that the prefix then does NOT show in the label on Prompt for User Input action.

Yes. Fortunately with the new HTML prompt this is no longer necessary. So —for HTML prompt macros— I can use the much nicer “dromedary” case (essPath). :wink: