Do I Need to Clear/Delete Local (Password) Variables?

For quite a while I have been using Keyboard Maestro macros to log in (using 1Password) into some "Apps" (which are single purpose browsers for services, so I can't use the 1Password extensions).

Credentials used to be stored in instance variables, but now in KM10 (with the introduction of subroutines) I converted them to local variables.

  • Do I still need to clear local variables, or are they "gone" when the macro has executed?
  • Can I combine variable types? Can I make the ones for passwords and OTP values both a local and a password variable by naming them localXXXpw?

Local variables only exist for the duration of the macro they are first used/defined in, so once that macro has ended, the value of the local variable is wiped out.

You can have local password variables, but be aware that the name of any local variable must begin with local.

EDIT: removed inaccurate information :-1:

1 Like

Hi @tiffle,

This is not true. See: manual:Variables [Keyboard Maestro Wiki]

Also, password may not need to use local variables. See:

1 Like

Thank you for sharing this. I've seen a lot of folks here saying that local variables are case sensitive...perhaps that's how it used to be; I'm not certain though because I've only been using Keyboard Maestro for about 3 years and only this year started to use local and instance variables.

I've never seen this statement on the forum before.

This can be easily tested with a macro:

Result :

As you can see, the value of localVar is reset by the value of LocalVar. They are basically regarded as the same variable.

Neither are global variables case sensitive:


I should probably correct myself, I haven't seen a LOT of people say it, but I have seen it come up a number of times the last few months.

I knew that it wasn’t actually case sensitive though because when I first started using them I never capitalized local and they always worked :laughing:

Thanks for the detailed reply though!

1 Like

Out of curiosity, I did a search on "Case Sensitive" on the forum. Here is what I found that might be related to what you were talking about. It's not the variable names that are case sensitive, it is the token names that are case sensitive.

KM7->8 Case Sensitive Variable - Questions & Suggestions - Keyboard Maestro Discourse


Awesome! For all I know I might have simply been misreading things to be honest. Thanks for the link.

Thanks for correcting me, @martin :+1:

I’ve said a couple of times in this forum that the designator for local variables is case sensitive, so I guess this is a change brought in with KM v10 perhaps. It’s good to hear because if in v9 you used local by mistake it would still work but you’d be using a global which could cause you problems.

I’ll certainly be confirming this for myself once I get my Mac back!

Anyway - it’s good to learn something new.

Edit: I see the wiki entry was edited in October, so perhaps this is indeed to do with KM10 but the release notes make no mention of it…

There has been no change, variables have always been case insensitive, “local” has always been case insensitive.

I went back and tested it in version 8, and it is exactly as @martin showed about, “localtest”, “LocalTest”, “LOCALTEST” are all the same local variable.

No. When the macro finished, local variables are gone.

Honestly, I wouldn't recommend it.

Either use a local variable, or use a password variable (and clear it when done with it).

I don’t believe a variable can be both a local variable and a password variable, and I don’t know how it would behave in which circumstances. And if I don’t know, that means it could change in the future no matter what it does today.

1 Like

That is curious indeed. I remember back in April when I started developing a complicated set of macros that depended on the use of local and instance variables I ran into problems with local variables seemingly persisting. After fiddling around (as every software developer does :zipper_mouth_face:) I found the solution was to capitalise the word ‘local’ in my variable names leading me to think that case is significant.

A quick search of the forum made me ROFL: in this post from June 2020 Local & Instance Variables Still Show in "Preference:Variable" - #4 by tiffle
I specifically tell @martin that case doesn’t matter.

Well, as it says in my profile - “This is my most recent senior moment... that I can remember