SeniorInquisitor SeniorInquisitor - 1 year ago 218
Bash Question

javascript do shell script

Newbee question -Now that OSX/Script can do javascript (, how do I change my applescript

set a to (do shell script "ls")
to the javascript syntax? From what I'm reading in the StandardAdditions.sdef, "doShellScript method : Execute a shell script using the ‘sh’ shell" is the command, so I tried,
doShellScript "ls"
, and the Script Editor (with the Script Language is set to JavaScript) returns, "Error -2700: Script error."

Answer Source

You have to tell your JXA script to use the Standard Additions.

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

sourcePath = "/Applications"

app.doShellScript("ls '" + sourcePath + "'").split("\r")

Enjoy, Michael / Hamburg

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download