Execute ExtendScript in InDesign from AppleScript

691 Views Asked by At

I can use AppleScript to send ExtendScript to Photoshop and get back the result:

This sends "2" to stdout:

tell application "Adobe Photoshop CC 2017"
    do javascript "var x = 2; x"
end tell

I get a syntax error when I try the same thing for InDesign 2015:

This results in a syntax error: Expected end of line but found application constant or consideration.

tell application "Adobe InDesign CC 2015"
    do javascript "var x = 2; x"
end tell

This similar code, using script instead of javascript does slightly better, resulting in this error message: Adobe InDesign CC 2015 got an error: A identifier can’t go after this identifier.

tell application "Adobe InDesign CC 2015"
    do script "var x = 2; x"
end tell

Any suggestions for getting this to work?

1

There are 1 best solutions below

0
On BEST ANSWER

The main difference is that "do script" is a specific command of the InDesign Scripting model in Applescript so its syntax is specific.

set myJavaScript to "var x = 2; x"
do script myJavaScript language javascript