2

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?

Example

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
ShooTerKo
  • 2,242
  • 1
  • 13
  • 18
aaronk6
  • 2,701
  • 1
  • 19
  • 28

1 Answers1

2

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

ShooTerKo
  • 2,242
  • 1
  • 13
  • 18
  • Thanks for the effort and greetings to Hamburg. It also looks like a bug to me—apart from the warning, the script is running totally fine. – aaronk6 Mar 05 '15 at 19:41