4

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?

superrache
  • 650
  • 11
  • 26
  • 1
    This question might have some answers for you http://stackoverflow.com/questions/3846626/is-it-possible-to-execute-jsx-scripts-from-outside-extendscript – fabianmoronzirfas May 19 '16 at 12:38
  • 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 Feb 13 '19 at 09:12

5 Answers5

7

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.

fabianmoronzirfas
  • 4,091
  • 4
  • 24
  • 41
  • 1
    thanks for you reply, I just tried the -run with a simple script targetting InDesign and showing the name of the app, it works. Unfortunately, doesn't work when I include some files from the script. InDesign is launched but no error appear. To avoid the untrusted sources warning, I put every scripts and library in My Documents\Adobe Scripts folder. – superrache May 19 '16 at 14:26
  • Can you provide an example? – fabianmoronzirfas May 19 '16 at 14:46
  • Yes of course. So, I created a script test.jsx (http://pastebin.com/aLFRpr9k) including a library include.jsx (http://pastebin.com/M7ZimmP4). Both files are in the Adobe Scripts folder. When executing from ExtendScript window, I get well the alert, but not when I run the following command: "C:\Program Files (x86)\Adobe\Adobe Utilities - CS6\ExtendScript Toolkit CS6\ExtendScript Toolkit.exe" -run "C:\Users\Kevin\Documents\Adobe Scripts\test.jsx" – superrache May 19 '16 at 15:54
  • 1
    Hm. I have the same problem. Without the `#include` statement everything works fine. With it the script wont execute. Sorry. Looks like a problem with the ESTK. I'm currently working on a command line tool that bundles ExtendScripts that use the `#include`or `//@include`. Maybe it is useful for you. https://github.com/fabiantheblind/extendscript-bundlr I will publish it to npm soon. – fabianmoronzirfas May 19 '16 at 16:27
  • Yes, it seems to be the solution to bundle every include files. I will follow your project. Thanks. – superrache May 22 '16 at 10:19
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.

Loic
  • 2,173
  • 10
  • 13
1

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);
styks
  • 3,193
  • 1
  • 23
  • 36
  • I am getting Error: Cannot find module 'spawn' and if I try to install this through npm, it shows npm ERR! 404 Not Found: webworker@https://github.com/mirkok/node-webworker/tarball/master. any thoughts? – Sameer Kumar Jain Oct 03 '18 at 16:32
  • 1
    spawn is a module of child_process in node. `const { spawn } = require('child_process');` https://nodejs.org/api/child_process.html – styks Oct 03 '18 at 20:53
  • I tried your solution, it open up indesign but it never run the script, the same script execute fine from script panel – Sameer Kumar Jain Oct 04 '18 at 11:32
  • sorry its working. Thank you. I am not able to pass dynamic arguments though. – Sameer Kumar Jain Oct 04 '18 at 12:41
  • @SameerJain What kind of arguments are you trying to pass? Are you trying to pass them to spawn? – styks Oct 04 '18 at 13:53
  • for example `var argsArray = new Array("Hello", "another hello");` and then in hostCommand args `"$app = new-object -comobject InDesign.Application;$app.doScript('${outputFilePath}', 1246973031, ${argsArray})"` – Sameer Kumar Jain Oct 04 '18 at 14:04
  • Its working now, `"$app = new-object -comobject InDesign.Application;$params=@('param1','param2');$app.DoScript('${outputFilePath}', 1246973031, $params)"` Thank you – Sameer Kumar Jain Oct 04 '18 at 15:24
0

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,

Loic
  • 2,173
  • 10
  • 13
0

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.

spyle
  • 1,960
  • 26
  • 23