osascript economises on Apple Event traffic and performs less sluggishly if we work with references to sets/collections of objects, batch-reading and batch-setting properties across these sets, rather than fetching and reading/mutating one object at a time.
In Applescript, to batch-read the colors of all lines on a layer, for example, we can write:
tell application "OmniGraffle"
tell canvas of front window
tell front layer
stroke color of lines
end tell
end tell
end tell
-- Returns:
-- {{0, 0, 65535}, {0, 0, 65535}, {0, 0, 65535}, {65535, 0, 65535}, {65535, 0, 65535}, {65535, 0, 65535}}
The JXA translation of this for batch-reading properties would be:
Application('OmniGraffle')
.windows.at(0).canvas
.layers.at(0)
.lines.strokeColor();
// Returns:
[[0, 0, 1], [0, 0, 1], [0, 0, 1], [1, 0, 1], [1, 0, 1], [1, 0, 1]]
Even more usefully, osascript allows for batch-setting of a property across a collection. To make all the referenced lines blue, for example, we can write, in AppleScript:
tell application "OmniGraffle"
tell canvas of front window
tell front layer
set (stroke color of lines) to {0, 0, 1}
end tell
end tell
end tell
The question is, what is the JavaScript for Automation translation for setting a property like this ?
(across a reference to a filtered collection of objects, without the much slower fetching of all objects and iterating through them, setting properties object by object)
If we try the obvious translation:
Application('OmniGraffle')
.windows.at(0).canvas
.layers.at(0)
.lines.strokeColor = [0, 0, 1];
We get an error, and the properties are not set.
What would be the correct syntax to batch-set the color of all lines on an OmniGraffle 6 layer ?
Or to put it another way, what type of arguments to the .setProperty() method on collections like .lines and .shapes (and on sets filtered by .whose()) allow us to set a property value across those collections ?