Using the runScript function to run a JXA script does not allow options

I am using JXA for a workflow script for Alfred 2 and recently tried to run a script from another script. I need to pass text between scripts, so I decided to use parameters, but whenever I try to pass a string, number, array or something else that is not an object for it, it gives an error " Error on line 4: Error: An error occurred.". If I pass an object, the second script (the one that runs the first script) gets an empty object, not the one that was passed to it. The same thing happens when the first script is AppleScript, but if the second script is AppleScript, everything works fine. Passing arguments through osascriptfrom the command line also works . Is the API broken or is there something I'm doing wrong?

First script:

var app = Application.currentApplication();
app.includeStandardAdditions = true;

app.runScript(new Path("/path/to/second/script.scpt"), { withParameters: "Hello World!" });

Second script:

function run(args) {
    return args;
}

Edit:

script , , , runScript script .

function run(args) {
    var app = Application.currentApplication();
    app.includeStandardAdditions = true;

    app.displayDialog(args.toString());

    return args;
}

2:

runScript , . , script, runScript, . , , .

Alfred 2

Alfred 2 ( , ..), , . , . , script script. Bash, , Alfred 2 . script ( , , ), script, ( ).

+4
1

, runScript, : script script.

script

script , script ~/Library/Script Libraries. script script.scpt , Script Libraries, script :

Library("script").run(["Hello, world!"])

Script JXA OS X 10.10, WWDC 2014, JXA, AppleScript.

script script

AppleScript Language Guide script Script Libraries. , , :

script, , , script s. , , .

, , script script, script script.

, script script.scptd, script embedded.scpt script.scptd/Resources/Script Libraries/embedded.scpt. Library('embedded') script.

script script, File > Export... script, File, File > Save As.... File Format Script bundle.

script, , Show Bundle Contents . , Script Libraries Resources, script .

0

Source: https://habr.com/ru/post/1626523/


All Articles