Inconsistencies in Lists of Stored KM Variables

This image shows an AppleScript that gets a list of all the variables that it believes currently exist, storing this list in the variable Result:

AppleScript
tell application "Keyboard Maestro Engine" to get the name of every variable

This image shows the contents of the variable Result immediately after the above AppleScript is run. The left-hand list shows the list of variables that the Keyboard Maestro editor believes currently exist:

Clearly, there is a big discrepancy, and this discrepancy is new, as of about three or four updates ago.

To see which is most likely to be at fault, I ran this action to retrieve the list of variables directly from the database:

Shell script
sqlite3 "/Users/$USER/Library/Application Support/Keyboard Maestro/Keyboard Maestro Variables.sqlite" "SELECT name FROM variables"

This returns an error: no such collation sequence: UNOCASE, which may be my poor SQL knowledge. So, instead, I ran the SQL query as:

SELECT name FROM variables WHERE value IS NOT NULL
Shell script
sqlite3 "/Users/$USER/Library/Application Support/Keyboard Maestro/Keyboard Maestro Variables.sqlite" "SELECT name FROM variables WHERE value IS NOT NULL"

and the list returned was most consistent with the AppleScript version of things:

Does anyone have any similar reports, or know what is going on ?

No, it's not your SQL, the database uses a case-insensitive collation function which will not be present except when done from within Keyboard Maestro. I'm not sure if there are any SQL applications that could cope with adding their own case-insensitive collation function.

In any event, AppleScript and the database include only variables that have a non-empty value. Variables without a value don't exist as far as Keyboard Maestro is concerned.

The editor Preferences window however lists all variables with values as well as all variables used within any macro in Keyboard Maestro.

There is a special case value of “%Delete%” which will show up in the database, but not in the AppleScript or Preferences window as well.

So all three can give different variable lists because they mean different things.

Peter, does it really need to be this way?
This seems to be a continual source of confusion.

In every other language I know, a variable is a variable is a variable, regardless of its value, which may be some value, a empty string, null, or undefined. So, if I have declared a global variable in any Macro, it should be visible everywhere, even if it is a empty string.

Now that we have Local and Instance variables as of KM 8, the need for and use of Global variables should be greatly diminished.

"Deleting" Global variables does not make any sense to me. If we want to lessen their impact to the environment, then we can set them to the empty string.

It also does not make sense to me to find Variables and Named Clipboards in KM Preferences. They have nothing to do with preferences. These lists should be available under the KM Editor View menu.

Please consider redesigning this for KM 9.

Thanks.

2 Likes