How to Loop Through and Delete All Variables

Over the years, especially before there were local variables, I created a whole series of global variables. Plus, there are a bunch that I still create as it is easier than passing parameters (at least for me).

When I searched for this all I found was how to delete a list of variables, so I'm posting this here for those who would like to clean out all global variables at once. Obviously, use this with caution.

1 Like

Hey @Stuart,

Please resize your Keyboard Maestro Editor responsibly before posting macro images.

Resize the Keyboard Maestro Editor for Sharing to the Forum

Take Care,
Chris

(Keyboard Maestro Moderator)

This has been done a time or two.  :sunglasses:

Your method works fine for deleting all global variables, but people frequently have some they absolutely DON'T want to delete.

This macro shows how to exclude variables by name and by partial-name from those deleted.

Delete All Variables Except… - #3 by ccstone

You could do something similar with your macro if desired.

You can also open the Keyboard Maestro Editor preferences to the variables panel, select-all (or some) and hit the Delete key.

-Chris

Thanks for the reply. I guess I just wasn't using the right key words to search. I tried delete all variables and loop through variables. I also didn't know about the preference panel having them there. But, I wanted to do it programmatically anyways.

Of course one can add a test saying if the variable <> X or Y or Z (via a switch) then delete it.