Why isn't $KMVAR variable displayed in terminal with an echo command?

In unix, the environment is passed down when you create a child process.

Something like this:

OS X starts up with process ID 1, which in OS X is /sbin/launchd. It sets up some sort of environment, including the environment variables. It then runs the loginwindow. loginwindow receives the environment passed down from launchd (possibly with changes). You then launch two applications, Keyboard Maestro and Terminal - each of these receive their environment variables from loginwindow. Keyboard Maestro launches Keyboard Maestro Engine which receives its environment from Keyboard Maestro. And Keyboard Maestro Engine runs your script, passing it the environment it has, together with all the KMVAR variables.

Terminal meanwhile has the environment passed to it from loginwindow - it knows nothing about the Keyboard Maestro variables and so when it runs a shell, that shell knows nothing about Keyboard Maestro variables.

You can retrieve the Keyboard Maestro variables via AppleScript requests to the Keyboard Maestro Engine, so you can get them from your script, but not in the form of KMVAR variables.

1 Like