如何从命令行执行 InDesign extendscript?

How to execute an InDesign extendscript from command line?

我需要从命令行 (Windows) 为 InDesign 执行 .jsx 脚本。

对于 Illustrator,使用以下命令即可轻松工作:

"C:\Program Files\Adobe\Adobe Illustrator CS6 (64 Bit)\Support Files\Contents\Windows\Illustrator.exe" "...\myscript.jsx"

Illustrator 和 ExtendScript Toolkit CS6 应用程序都会打开,然后脚本会自动启动。

当我对 InDesign 尝试同样的方法时,它不起作用(InDesign 说 'Unable to open myscript.jsx ...')。

我还尝试从命令行启动 ExtendScript Toolkit,如下所示:

"C:\Program Files (x86)\Adobe\Adobe Utilities - CS6\ExtendScript Toolkit CS6\ExtendScript Toolkit.exe" "...\myscript.jsx"

结果是 ExtendScript Toolkit 应用程序在加载脚本的情况下打开,但未执行任何操作。

有人知道如何启动脚本吗?是否要添加 -run-cmd 参数?

对我来说 Osx 它是这样工作的:

/Applications/Adobe\ ExtendScript\ Toolkit\ CC/ExtendScript\ Toolkit.app/Contents/MacOS/ExtendScript\ Toolkit -run test.jsx

在 Windows 上应该是:

"\path\to\ExtendScript Toolkit.exe" -run test.jsx

test.jsx 的内容:

//@target indesign
alert(app.name);

它需要 -run 标志。使用 -cmd 时,它仍然执行脚本,但来自 ESTK。 //@target indesign 被忽略。使用 -run 脚本将传递给 InDesign。不幸的是,ESTK 会弹出一个对话框,警告执行来自不受信任来源的脚本。

您的解决方案可能是从命令行调用 visualbasic 脚本。然后 VB 将根据引用的 indesign 应用程序本身调用 indesign jsx 文件。有点棘手,但应该绝对有效。

我手头没有 Windows 来实际测试它,但我会先查看这些链接: 运行 VBS 在命令行中:http://ss64.com/vb/cscript.html

运行 InDesign VB:https://www.google.fr/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0ahUKEwjj9_3JoPXMAhVI1BoKHUKMBT8QFggfMAA&url=https%3A%2F%2Fwww.adobe.com%2Fcontent%2Fdam%2FAdobe%2Fen%2Fdevnet%2Findesign%2Fsdk%2Fcs6%2Fscripting%2FInDesign_ScriptingGuide_VB.pdf&usg=AFQjCNFP8M8i3xrOqLp0zw3BGcNpnyhEXQ&sig2=pfFYnsgxXDpCf1A573JTDQ&bvm=bv.122676328,d.d2s

查看用于调用 JSX 脚本的 DoScript 方法。 myInDesign.DoScript 我的JavaScript,

如果您尝试使用节点执行,这是我发现的执行 Indesign 脚本的两种最佳方式。

  • 版本无关

信用 rendertom inside his vscode/atom 插件。

const outputFilePath =  path.resolve(os.homedir(), 'Documents', 'Adobe Scripts', 'myscript.js');
const hostCommand = {
        darwin: {
            command: 'osascript',
            args: [
                '-e',
                `tell application id "com.adobe.indesign" to do script "${outputFilePath}" language javascript`
            ],
            options: {}
        },
        win32: {
            command: 'powershell',
            args: [
                '-command',
                `"$app = new-object -comobject InDesign.Application; $app.DoScript('${outputFilePath}', 1246973031)"`
            ],
            options: {shell: true} // Windows requires a shell
        }
    };

    if (typeof hostCommand[process.platform] == 'undefined') {
        throw new Error('This platform is not supported');
    }

    const {command, args, options} = hostCommand[process.platform];
    const p = spawn(command, args, options);

如果没有 ExtendScript Toolkit 并且在 Mac 上,您可以使用 AppleScript 或 JavaScript 进行自动化 (JXA)。

这就是在 jasminejsx 库中如何在 ExtendScript 中执行 jasmine 规范。

osascript -l "JavaScript" -e "var app = new Application('com.adobe.indesign'); app.doScript('$EXTENDSCRIPT', {language: 'javascript'});" &

See code here.