SeniorInquisitor SeniorInquisitor - 7 months ago 86
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."


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