Good. That answers the question about which OmniFocus JSContext
(and thus which OmniFocus scripting library) you are working with.
The answer is both
Let's call them:
- The JXA interface (same interface library as AppleScript, just using JS). It's built on Apple Events passing between different applications. Easy enough to pass KM variable values this way, and your
Application("Keyboard Maestro Engine").getvariable
example shows this. - The omniJS interface (they now call it "Omni Automation" – too long) is used by a JSContext built into OmniFocus itself, which it make it fast, but not directly equipped to easily exchange information with other applications. A bit harder to get KM variable values into this, but not impossible.
What you are doing, in the example
Application('OmniFocus').evaluateJavascript(
`(${omniJSContext})()`
)
Is using JXA's Application('OmniFocus').evaluateJavascript
method to send a JS code string into omniJS for evaluation in there.
One JSContext
for preparing and handing over the code,
and another, completely separate, JSContext, with different libraries, to run the code.
In that scenario:
- We can't set KM variable values from inside the omniJS JSContext (it's largely isolated from inter-application communication - KM's
setvariable
method is not defined in it, - and we can't directly read values from KM either – KM's
getvariable
method is not defined in it, - but we can squirrel values obtained from KM into the source code handed over from
JXA
intoomniJS
with the.evaluateJavaScript
method.
Stepping back for a moment, if KM ⇄ OmniFocus value passing is central to the scripts which you want to set up, then the omniJS
JSContext is not really the right one to use. It's fast and actively maintained, but it's not really built for that purpose.
You may be better off using a purely JXA solution.