JXA and local variables: "A privilege violation occurred"

I can't figure this out.

I'm trying to create a JXA script that accesses a local variable. To do that, I need to capture the KMINSTANCE. But since this is a global macro, I want to use const app = Application("Google Chrome") rather than const app = Application.currentApplication()

The former gives me "Error: A privilege violation occurred. (-10004)" when I try to access the KMINSTANCE. Everything is fine if I use a global KM variable, but that's poor.

SOMEONE must know what I'm doing wrong. And thank you

I wouldn't even recognize JXA if I saw it, so feel free to ignore my ideas. I won't mind. But I googled it and found a web page with a similar issue:

And I also recall that privilege problems with KM are also caused by not having the correct KM or macOS apps loaded into the System Preferences / Security & Privacy / Privacy / applist.

So my chances of being right are under 10% since I hardly know what I'm talking about so feel free to ignore me.

You must first use the currentApplication to get the KMINSTANCE object, as shown in the KM Wiki:
How To Get/Set Keyboard Maestro Local & Instance Variables

Thanks both of you.

JM: I would have told you that I'd already tried exactly that, but I would have been wrong. It works, just as suggested. Thanks again.

1 Like