Reputation: 2811
When using Application.currentApplication()
in an OSA script, it issues the following warning when running it from the command line:
warning: failed to get scripting definition from /usr/bin/osascript; it may not be scriptable.
Why is this happening and what can be done about it?
app.js:
#!/usr/bin/env osascript -l JavaScript
var app = Application.currentApplication();
app.includeStandardAdditions = true;
console.log('Hello, I’m ' + app.pathTo(this));
Shell Output:
❯❯❯ ./app.js
2015-03-01 12:39:29.611 app.js[65539:6266286] warning: failed to get scripting definition from /usr/bin/osascript; it may not be scriptable.
Hello, I’m /Users/aaron/Desktop/app.js
Upvotes: 2
Views: 1137
Reputation: 2282
the JXA Release Notes says the following:
6. Getting the application that is running the script
Application.currentApplication()
And yes, I thought it would give me an script object pointing to my script itself, too.
I tested it directly inside the Skript-Editor using your JavaScript:
var app = Application.currentApplication();
app.includeStandardAdditions = true;
console.log('Hello, I’m ' + app.pathTo(this));
and the Events tab gave me
app = Application("Skript-Editor")
app.pathTo(null)
/* Hello, I’m /Users/.../Desktop/app.scpt */
When running this app.scpt from osascript
the function currentApplication()
returns osascript and the environment warns that the app may not be scriptable... Is it a bug? I don't know, osascript IS the executing app AND it is not scriptable :-/
But otherwise: How can app
execute the function pathTo
then and why is null
passed to it?
just my 2 cents... Michael / Hamburg
Upvotes: 2