How do I convert the name of a variable to a string

Hello,

Lets say I have a variable named pretext and I wish to get the name of that variable as a string, not the name assigned to the variable pretext.

Ben

An osascript incantation (AppleScript or JavaScript) can harvest a list of variable names:

In an Execute AppleScript action:

tell application "Keyboard Maestro Engine"
    name of variables
end tell

or in an Execute JavaScript for Automation action:

Application("Keyboard Maestro Engine")
.variables
.name()

but perhaps you are looking for a route from the variable's value string to its name string ?

For example, to list the name strings of all or any variables which have the value "VLC" in my Keyboard Maestro installation:

I might write (in an Execute JavaScript for Automation action)

(() => {
    "use strict";

    const valueString = "VLC";

    return Application("Keyboard Maestro Engine")
        .variables.where({
            value: valueString
        })
        .name();
})();

and on this system, evaluating:

yields:

Expanding on @ComplexPoint's AppleScript, this one just returns all the KM variables whose value contains the string http

tell application "Keyboard Maestro Engine"
	name of variables whose value contains "http"
end tell

Obviously, you can change http to whatever it is you're looking for and you can use the normal KM conventions for passing it as a variable to the script.

On my Mac this script returns the following:

KM 0 2022-03-12_12-48-25

Here it is in full:

Test Get KM Variable Names.kmmacros (1.7 KB)

2 Likes