Skip to main content
heatherw6960836
Inspiring
July 30, 2019
Answered

How to run JSX Script from JavaScript or CFScript

  • July 30, 2019
  • 4 replies
  • 9959 views

I'm trying to find a way to execute a JSX Script externally.  Say it is named CreateMasterDocument.jsx.  It contains functions that manipulate InDesign documents.

I originally wanted to find a way to pass parameters to this JSX function below, as well as run it from JavaScript or CFScript (we use both); however, I can most likely read in this JSX file, and manipulate the first line "createStagingDocument(3,6,9,27);", then re-save the file.  But still need to launch this JSX file.

Any ideas how to execute the JSX file from JavaScript?

Thanks,

Heather

//uncomment for testing

createStagingDocument(3,6,9,27);

function createStagingDocument(AccountID, SourceDocumentFolderID, StagingCampaignID, StagingDocumentID)

{

    //the function that manipulates InDesign and XMPie plugin, documents....

}

This topic has been closed for replies.
Correct answer heatherw6960836

Hi all,

What I ended up doing is creating a BAT file.

Then have my webpage execute/run the BAT file. The BAT file executes the JSX script.

Example (BAT file: RunJSXScript.bat).  It's content:
"C:\Program Files (x86)\Adobe\Adobe ExtendScript Toolkit CC\ExtendScript Toolkit.exe" -run \\123.456.78.09\AFolderNameHere\MyScript.jsx

Additionally, I modified the JSX Script before execution as I needed to have parameters passed.  And that was another obstacle. So the way I found around it was to use JavaScript code to read in the JSX file to a temp file, replace certain variables with real values (therefore modifying the file), then saving the file.  Then it is ready to be run for that instance.

4 replies

Loic.Aigon
Legend
August 9, 2019

Hi Heather,

Remember to check EULA though and if your implementation fits

heatherw6960836
heatherw6960836AuthorCorrect answer
Inspiring
August 6, 2019

Hi all,

What I ended up doing is creating a BAT file.

Then have my webpage execute/run the BAT file. The BAT file executes the JSX script.

Example (BAT file: RunJSXScript.bat).  It's content:
"C:\Program Files (x86)\Adobe\Adobe ExtendScript Toolkit CC\ExtendScript Toolkit.exe" -run \\123.456.78.09\AFolderNameHere\MyScript.jsx

Additionally, I modified the JSX Script before execution as I needed to have parameters passed.  And that was another obstacle. So the way I found around it was to use JavaScript code to read in the JSX file to a temp file, replace certain variables with real values (therefore modifying the file), then saving the file.  Then it is ready to be run for that instance.

Sunil Yadav
Legend
August 8, 2019

If you can execute batch file.

Try this way.

Instead of using ExtendScript Toolkit.exe.

Execute VBS from where you should execute JSX.

Like this:

This is your command line arguments:

wscript.exe D:\SunilY\Test\vbScript.vbs

This is my vbScript.vbs content:

Set myInDesign = CreateObject("InDesign.Application.CC.2017")

dim myArray, myString

myTestJavaScript = "D:\SunilY\Test\test.jsx"

myInDesign.DoScript myJavaScript, 1246973031

Take a loot at this link: ----->  Run script from command line

Best

Sunil

heatherw6960836
Inspiring
July 31, 2019

Hi guys,

I'm trying to call/execute the InDesign Script, JSX  file, not from within another JSX file but from an external, native JavaScript (JS) file or external web page (CFM/HTML or the like).

Loic.Aigon
Legend
August 1, 2019

oh well if you talking about running an indesign script from a web page, putting aside CEP extensions (basically HTML plugins run inside the app), the most obvious technical and legal answer would be to use InDesign Server and a SOAP request. If its' more "local" and for your own use then you can use sth like PHP to call command line and drive ExtendScriptToolKit (but not for long) :

ExtendScript Toolkit · fabianmoronzirfas/extendscript Wiki · GitHub

Or you could have a InDesign Plugin listening for events thrown from your web page (webhook?) and execute the jsx script. There are many options but none of them is trivial.

BarlaeDC
Community Expert
Community Expert
July 31, 2019

HI,

I am not entirely sure what you are trying to achieve, but you can use $.evalFile method to run a JSX file.

As seen here - https://www.indesignjs.de/extendscriptAPI/indesign-latest/#$.html#d1e62__d1e437

not sure how that could be plugged into your workflow.

Regard

Malcolm

Loic.Aigon
Legend
July 31, 2019

Hi Heather,

You may want to include the external jsx to your main script :

/////file.jsx

function callMyExternalFunction(){

alert("hey there");

}

///main.jsx

#include "/some/path/to/the/file.jsx"

//calling function from external jsx

callMyExternalFunction(); //Display "hey there"