AppleScript Error [Solved – invalid variable name]

Hi There!

For some reason, my KM isn't allowing AppleScript to query it for variables and the like. I get the following error:

I'm assuming it's a permissions thing, but I can't even allow AppleScript access to KM in the "Automation" tab in Privacy and Settings, as seems to be the thing to do.

For context, here's the code:

tell application "Keyboard Maestro Engine"
	set KM-Caffeinate to getvariable "Caffeinate"
end tell

Anyone have any ideas on how to get this to work?

You cannot use the hyphen "-" character as part of an AppleScript Variable's name. Try renaming the AppleScript Variable "kmCaffeinate"

1 Like

Got it, thanks! That's what it says in the official documentation from KM, so I'll add a note for them to change this.

Are you sure you're not mistaking a hyphen for an underscore?

If in fact you're correct about the docs – please provide a URL.

Take Care,

(Keyboard Maestro Moderator)

As Chris suggests, I think they may just point you here:

AppleScript Lexical Conventions

where the character set for AppleScript identifiers is defined.

(It includes underscore _, but not hyphen -)

You many notice, in fact, that their examples of invalid identifiers actually include an attempt to use a hyphen:

The following are not valid identifiers: C-, back&forth, 999, Why^Not.

Hyphen - is effectively reserved for the minus operator.

Consider, for example:

on run
    set KM to 10
    set Caffeinate to 7
    return KM-Caffeinate
    --> 3
end run