superrache
superrache

Reputation: 670

How to execute an InDesign extendscript from command line?

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?

Upvotes: 3

Views: 9485

Answers (5)

spyle
spyle

Reputation: 2008

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.

Upvotes: 0

styks
styks

Reputation: 3451

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

Upvotes: 1

Loic
Loic

Reputation: 2193

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,

Upvotes: 0

Loic
Loic

Reputation: 2193

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.

Upvotes: 1

fabianmoronzirfas
fabianmoronzirfas

Reputation: 4121

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.

Upvotes: 7

Related Questions