How to execute an InDesign extendscript from command line?

北慕城南 提交于 2020-07-18 07:38:10

问题


I need to execute a .jsx script for InDesign from command line (Windows).

For Illustrator, it works easily with the following command:

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

Both applications Illustrator and ExtendScript Toolkit CS6 open then the script is automatically launched.

When I try the same for InDesign, it doesn't work (InDesign says 'Unable to open myscript.jsx ...').

I also tried to launch ExtendScript Toolkit from command line as below:

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

The result is ExtendScript Toolkit application is opened with the script loaded, but nothing is executed.

Does anyone know how to launch the script? Is there a -run or -cmd argument to add?


回答1:


a solution of yours could be to call a visualbasic script from command line. That VB would then call the indesign jsx file based on having referenced teh indesign application itself. Kind of tricky but should definitively work.




回答2:


For me on Osx it works like this:

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

On Windows it should be:

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

content of test.jsx:

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

It needs the -run flag. When using -cmd it still executes the script but from ESTK. The //@target indesign gets ignored. With the -run the script gets passed to InDesign. Unfortunately the ESTK brings up a dialogue that warns to execute scripts from untrusted sources.




回答3:


If you are trying to execute using node, these are the best two ways I have found to execute Indesign scripts.

  • Version Agnostic

Credit rendertom inside his vscode/atom plugins.

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);



回答4:


I don't have Windows at hand to actually test it but I would start by looking at those links: Run VBS in command line : http://ss64.com/vb/cscript.html

Run InDesign in 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

Look at the DoScript method for calling a JSX script. myInDesign.DoScript myJavaScript,




回答5:


Without ExtendScript Toolkit and on a Mac, you can use AppleScript or JavaScript for Automation (JXA).

This is how it's done in the jasminejsx library to execute jasmine specs in ExtendScript.

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

See code here.



来源:https://stackoverflow.com/questions/37320580/how-to-execute-an-indesign-extendscript-from-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!