Copy link to clipboard
Copied
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....
}
1 Correct answer
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 JavaScrip
...Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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"
Copy link to clipboard
Copied
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).
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
No need for a plugin - you can access InDesign from platform specific scripting architectures. You just have to figure out how your application server (php, node.js) can call those.
On MacOS the scripting architecture would be AppleEvent, as used by AppleScript.
To launch a JSX, you'd pass it as argument to their equivalent of app.doScript - it takes either a file or jsx code.
tell application id "com.adobe.indesign" to do script "alert('Yo!')" language javascript
I've rarely seen it in the wild and never tried it out, but Apple even has an own JavaScript alternative to AppleScript.
Mac Automation Scripting Guide: About Mac Scripting​
I guess that qualifies as external, native JavaScript?
On Windows some keywords are CreateObject, TLB, type library, COM, eventually DCOM ... .
If you think an application server is overhead, InDesign also has its own built-in web browser - the technology is called CEP.
For scenarios where you expose InDesign to the web beyond the browser runnnig on the operator's workstation, there is also InDesign Server with some more options and appropriate license.
Copy link to clipboard
Copied
Right. Here is an example of a CEP panel using a webhook to catch HTTP post requests from the web:
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Hi guys
What we wanted to accomplish was executing the JSX from our website that is written in JavaScript, JQuery, Bootstrap, ColdFusion, CFScript. We were not trying to run the JSX within InDesign. It has to be lauched as part of our other automated processes fired from external web processes.
We could have tried to possible get webservices and SOAP running, but we were successful in using our CFEXECUTE and running BAT or EXE etc. CFEXECUTE is specific to ColdFusion (part of our web development software which also happens to be an Adobe product). So this would not work for just anyone. But just wanted to let people know you can execute JSX files with a BAT file. You just have to find out how to execute the BAT file from your web development programming platform. Many use VB, other use the ActiveXObject but this is very specific to using Internet Explorer and we primary use Chrome.
But wanted to share it anyway,
Heather
<HTML><HEAD>
<script type=
"text/javascript"
>
function myFunction(){
WshShell =
new
ActiveXObject(
"Wscript.Shell"
);
//Create WScript Object
WshShell.run(
"d://temp/testJS.bat"
); // Please change to your location
}
</SCRIPT>
</HEAD>
<BODY>
<H1>Execute BAT from JavaScript</H1>
<INPUT TYPE=Button Name=btn Value=
"Test Java Script"
onClick=
"myFunction()"
>
</BODY>
</HTML>
Copy link to clipboard
Copied
Hi Heather,
Remember to check EULA though and if your implementation fits

