Use ESTK for developing or debugging a JavaScript based scripting solution for Adobe InDesign, InCopy, or InDesign Server with the censhare plug-in XMLCommand.

The solution will automatically open the to be executed JavaScript script in ESTK, which allows using its single step features, breakpoints, provides extended error information and context, and enables inspection of the scripting DOM.

This feature is implemented in the plug-in version 2.8.29. It works with any censhare Java Client or Renderer Client on both MacOs and Windows. It requires the ESTK to be installed, which is either installed with InDesign, or can be downloaded and installed separately via Adobe Creative Cloud, depending on the product version.

Example

Here is a simple XML command containing a JavaScript to calculate the number of frames placed in the frontmost document.

To test this script activate your Java client’s admin mode. Then from the menu Admin:

  • Open the LayoutInterface Test window
  • Select the target application
  • Paste the below script into the “Input” text area
  • Hit Execute

<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
<commands>
<command method="run_script" uid="Df">
<result name="censhareResult" value=""/>
<script language="javascript">
var targetDocument = {}, pageItemCount = 0;
// Always operate on frontmost document.
targetDocument = app.documents.item( 0 );
pageItemCount = getPageItemCount( targetDocument );
app.scriptArgs.setValue( "censhareResult", pageItemCount.toString() );
function getPageItemCount( targetDocument ) {
var pageItemCount;
pageItemCount = targetDocument.allPageItems.length;
return pageItemCount;
};
</script>
</command>
</commands>
</root>

Note! We recommend to set the Timeout to 500, as the default timeout is too short and execution will timeout while i. e. using ESTK single stepping.

The result of the execution is represented as XML in the “Output” area. Looking into the nodes of the output XML, the result we are looking for is the first node below our command:

<result name="censhareResult" value="#"/>

To automatically have the ESTK launched and stop prior executing the first JavaScript line, add the parameter invoke_debugger to the command as shown below:

<command method="run_script" uid="Df" invoke_debugger="true">

When the script is executed ESTK is automatically launched and you can use it’s debugging features (single step, breakpoints, inspect the scripting DOM).

estk.png

Please note that you have to finish the execution of the script inside ESTK before the control is passed back to the calling application, the LayoutInterface Test in our case.

Error processing

There are some times where the returned error is not very helpful and the plug-in has no access to the error on the internal JavaScript engine of the Application (InCopy, InDesign etc) or ESTK.

In such cases it’s better to get the extended error information directly from the application, without using ESTK. To do that, simply add the show_error_alert parameter in the run_script command to allow the application to display an alert for the JavaScript error.

<command method="run_script" uid="Df" show_error_alert="true">

Demonstration

A scenario like that can be demonstrated by removing the following line from our example:

pageItemCount = targetDocument.allPageItems.length;

The returned result will be undefined, as the local variable pageItemCount doesn’t have a value set, while ESTK will break at the offending line with additional information and context. Without specifying the invoke_debugger="true", the returned error to the client would be the following: “Execution of script resulted in error #21.” (Bei der Ausführung des Skripts ist der Fehler #21 aufgetreten.)

While when enabling the show_error_alert this is what InDesign will return:

inDesignAlert.png

In case both options (invoke_debugger and show_error_alert) are set, ESTK will stop at the error and after finishing ESTK’sexecution, InDesign will show the error alert.

Note!: Please make sure that none of these options are set to true for scripts used in a production environment.