KM variables are global: what about local use without conflict?

KM variables, listed as:

Keyboard Maestro variables list.kmmacros (29.3 KB)

are globales...

How to manage local use (emulating local variables in fact) avoiding conflict in Execute Macro Action call's chain?

Any ideas, thanks,

Hey Alain,

That macro gets the job done but is more complicated than necessary for simply displaying the variables.

Even so – your usage of the different KM actions shows you've come a long way, since you started.

Just for giggles here's my more generic Keyboard Maestro environment dumper macro:

Keyboard_Maestro { Dump_Env env }.kmmacros (2.1 KB)

It can easily be adjusted to use TextEdit instead of BBEdit as the viewer. (TextWrangler could easily replace BBEdit as well if its command-line tools are installed.)

On to Global vs Local Variables in Keyboard Maestro.

Keyboard Maestro has NO concept of Local. All variables are Global.

If you really need a local variable you can write-to and read-from the defaults system using the shell.


You can write-to and read-from 1 or more files.

Create a folder somewhere called Keyboard_Maestro_Variables, and give it a sub-folder structure that makes sense for your context.


Keyboard Maestro has read-from-file and write-to-file actions, so that's easy.

You can also easily read/write from AppleScript.

There are some other methods, but these are the simplest.


Of course :blush: Thanks to point out and for your dumper. First, I want to use KM to process further and change my mind…

Focusing on KM “local” variables:

Could you elaborate? How is the naming (name space)?


Hey Alain,

I’m not more than a casual user of the defaults database.

Accessing it from the shell is a bit slow, so I’m unlikely to fool with it more than I have to until I can access it more quickly with ASObjC or something else.

Here are a couple of reference points:

Here’s a working example:


defaults write com.ccs.prefs prefVal01 -bool true


defaults read com.ccs.prefs prefVal01


defaults delete com.ccs.prefs prefVal01

com.ccs is me, although that’s only on my machine.

I would not use this system for prefs.

I would either use a system of text files, as I described earlier.


I’d use a single .plist file and operate it with System Events or the Satimage XMLLib.osax (preferably the latter).


I’d use a flat text file and the Satimage.osax’s regEx (or KM’s regex).

Reading and writing to/from a file is very fast unless the file is quite big.


Thanks Chris for your detailed stimulating tracks.

I will come back if something which deserve sharing appears.