Here is my issue. This JXA script works well, returning '/' as current wd:
And the following JXA script gives an error -10004 and refuses to start:
Can anyone explain why can't I use .doShellScript(), when app is created from "Keyboard Maestro Engine"?
Thanks for trying to help. Error -10004 is A privilege violation occurred.
Looks like this is one of the mysterious JXA issues:
Why do you want to use the KM app to run shell scripts?
Just about all examples I have seen that use
.includeStandardAdditions do so applied to the Current Application.
Since that works for you, what not use it?
There is not any special reason. I was already using KM app in this script, so I wanted to use an existing reference instead of creating another one to CurrentApplication.
The KM Engine is NOT a good app for general purpose use in either JXA or AppleScript.
So, for all of my JXA scripts, I have a template with this at the top:
var app = Application.currentApplication()
app.includeStandardAdditions = true
This is especially needed if you want to do any type of UI, like
For more info on JXA, see:
As that’s such common boilerplate I wonder if Keyboard Maestro could automatically generate it at runtime - with a tick box to enable it.
(I’ve just started using Keyboard Maestro as a test bed for learning JXA and this particular incantation seems near universal to me.)