applescriptosascriptjavascript-automation

How to call a shell command from JavaScript JXA?


I have an AppleScript script that is calling a shell command that I want to convert to JavaScript (JXA) but I don't see the equivalent of do shell script.

Here is the script using AppleScript:

#!/usr/bin/osascript

on run argv

    set convertScript to "export -i '" & first item of argv  & "' -o '" & second item of argv & ".csv'"

    do shell script convertScript

end run

My desktop application calls this script and then the script executes the shell command.


Solution

  • It is possible using the following command:

    var app = Application.currentApplication();
    app.includeStandardAdditions = true;
    return app.doShellScript('ls');
    

    From here.