2
votes

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?

5
This question might have some answers for you stackoverflow.com/questions/3846626/… - fabianmoronzirfas
I have no ready to use solution, but if you know a port of your started InDesign server you can start script like this: \Adobe InDesign CC Server 2018\sampleclient" -host localhost:12345 ./your-script.jsx the InDesign server's port could be achieved by a combination of windows commands taskslist, netstat, find - KEMBL

5 Answers

1
votes

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.

6
votes

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.

1
votes

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

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.