从 AppleScript 在 InDesign 中执行 ExtendScript

Execute ExtendScript in InDesign from AppleScript

我可以使用 AppleScript 将 ExtendScript 发送到 Photoshop 并取回结果:

这会将“2”发送到标准输出:

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

当我对 InDesign 2015 尝试同样的操作时出现语法错误:

这会导致语法错误:Expected end of line but found application constant or consideration.

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

这个类似的代码,使用 script 而不是 javascript 效果稍好,导致此错误消息: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

有什么建议可以让它发挥作用吗?

主要区别在于"do script"是Applescript中InDesign脚本模型的特定命令,因此其语法是特定的。

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