Kme.variables.name()?

I was looking at some code by @JMichaelTX, and I saw this:

var kmeApp = Application("com.stairways.keyboardmaestro.engine")
var kmVarNameArr = kmeApp.variables.name()		

I can’t find this in KME’s dictionary. I’m sure I just don’t know what I’m doing. Can someone tell me how, if I hadn’t seen this in someone’s code, I’d know it’s available?

And how, if possible, What’s the AS syntax for this?

Thanks!

The name property of the Variable object is there in the sdef

As in Script Editor > File > Open Dictionary

Yeah, but where’s “variables” - plural?

The application contains a variables collection - the convention is that the collections are lowercase with an affixed s, and the class name of an individual element of a collection is singular.

(the class constructor function is singular with an initial uppercase)

Well, that’s interesting.

  1. I don’t see this information in Script Debugger’s version of Dictionary.

  2. That appears to be the only place where “variables” (plural) are mentioned. There’s things like “getvariable” and “executing”. Why wouldn’t “variables” be mentioned somewhere else?

Well, Script Debugger doesn't read the .sdef in JS format, only in AS format, so its only an indirect guide to JS usage, but take a look, for example, in the Script Debugger Explorer panel:

1 Like

Ooooh, good one! I totally didn’t see that tab. Wow, that’ll be useful! :slight_smile:

Thanks a million!

SD is showing you the AppleScript Dictionary.
The JXA Dictionary, shown in Script Editor, is slightly different.

var kmeApp = Application("com.stairways.keyboardmaestro.engine")
var kmVarNameArr = kmeApp.variables.name()

The AppleScript equivalent of this is:

tell application "Keyboard Maestro Engine"
	set kmVarNameList to name of every variable
end tell

Note that JavaScript uses "array" where as AppleScript uses "list", for essentially the same collection. So, my variable suffix is set accordingly.

It's just a syntax difference between JXA and AppleScript.

In general, AppleScript does NOT use plural names.
Instead, it uses the every reference form, as in every variable

For more info, see Reference Forms in AppleScript Language Guide

Actually, this works:

tell application "Keyboard Maestro Engine"
	set _variables to variables
end tell

By the way, how do you get AppleScript syntax hilighting in a post? I know how to do javascript.

Yep, it does, but I rarely see any AppleScript code that uses that form.

For example, when I ask SD to paste a tell block for the "variables" element, it pastes this:

every variable

So, every variable may be easier recognized by other users than variables.

But it's your code. Use whatever you like. :smile:

1 Like

Same as JavaScript, just use "applescript" instead of "javascript" after the 3 backquotes:

```applescript
your code
```

I swear I tried that. Must have fat-fingered something.

Thanks.

I should have done this long ago. See:

1 Like

Never quite sure what this business with urgent capital-shouting is really about,
but I have to say that this is a pontifical pronouncement which slightly puzzles me.

I somehow seem to have written tens of thousands of lines of AppleScript without ever once typing the word every, despite making rather intensive use of the batch-reading and batch-setting of collections.

Taste and usage varies, not sure that there's an urgent need to police it.

(I personally happen to be a bit unconvinced by the alleged clarity of these elements of aspirant 'Englishness' in AS, especially where they simply make it more verbose, and split linked morphemes with white space).

Many things seem to puzzle you, while your esoteric language fails to communicate with most.

If you have a technical point, please make it and leave the commentary off.

@JMichaelTX, @ComplexPoint - Guys, time to put a lid on this one, don’t you think? Or at least take it to private messages?

1 Like