The Adobe Creative Suite applications (Acrobat, Photoshop, Illustrator and InDesign) can be extensively scripted through JavaScript (a scripting language interpreted and executed by the application). All four applications offer a similar overall interface for working with JavaScript, although each application offers a different set of JavaScript functions to actually control the application's functionality
The JavaScript programming interface for each application is documented in the application's software development toolkit which can be found on the Adobe web site. The Adobe Creative Suite bundle includes the "ExtendScript Toolkit" application which is extremely useful for developing and debugging JavaScript scripts for Adobe Creative Suite applications.
The Switch configurators for the four applications mentioned above allow posting a JavaScript script to the application for execution. Combined with Switch's built-in capabilities this provides powerful control of the Adobe Creative Suite applications.
A configurator defines the action to be executed by its corresponding application in the form of three consecutive stages:
Open the file and make it the currently active document.
Perform a command on the currently active document.
Save the currently active document and close it.
The desired action for each stage is defined independently, and can be selected from:
One of the built-in actions listed by name.
A user-provided script (which is specified by browsing to a JavaScript text file).
Depending on the selected action a number of subordinate properties are shown to further configure the action. In other words, each choice has its own set of properties.
The properties for the "Use script" choice are described below; those for built-in choices are described for each configurator separately.
The following set of properties is shown for an action stage if the "Use script" option is selected for the stage.
Property |
Description |
|---|---|
Script file |
The text file that contains the JavaScript script to be executed by the application for this stage |
Argument 1 |
The first argument to be passed to the script (or empty) |
Argument 2 |
The second argument to be passed to the script (or empty) |
Argument 3 |
The third argument to be passed to the script (or empty) |
Argument 4 |
The fourth argument to be passed to the script (or empty) |
Argument 5 |
The fifth argument to be passed to the script (or empty) |
There are always five arguments because there is no mechanism to determine how many arguments are actually needed by the script.
To write a user script, simply provide the JavaScript statements that should be executed in the main body of the script file. If your script encounters an error, it should set the $error variable to the appropriate error message; otherwise it should leave the $error variable alone. See below for a typical coding pattern.
The following special global variables are defined before your script executes, and thus their value can be used in your script; in some cases (noted in the variable's description) your script should also set or update the contents of the variable.
Here's a typical coding pattern to correctly handle errors in a user script attached to the command action:
if ($error == null)
{
try
{
// statements to be executed by this script
// $doc.ApplicationDependentFunction();
}
catch( e )
{
$error = e.description;
$status = failJob;
// This will move the failed job to Problem Jobs folder. If not set, the
default is the “Error” level data connection.
$doc.closeDoc( Application Specific Parameters );
// close any other resources used in the try block
}
}
<AdobeConfiguratorLog>
<FlowElementName>ConfiguratorFlowElementName</FlowElementName>
<Job>
<Name>NoFontPackage</Name>
<Status>Error</Status>
<StatusMessage>Error Message String</StatusMessage>
<MissingFonts>
<Font>Somora</Font>
<Font>XBAND Rough</Font>
</MissingFonts>
<Job>
</AdobeConfiguratorLog>
Here's a typical coding pattern to correctly handle errors for Adobe Acrobat application:
// Acrobat is used to make a summary of the annotations resulting in a file that shows you the page
// content and the annotations per page.
// No arguments are required.
if($error == null)
{
try
{
var title = $doc.documentFileName + " summary"
$outfile = $outfolder + '/' + $filename + "_summary.pdf";
$doc.ANsummarize($doc, title, ANSB_Page, null, $outfile, null, false, true, false, false, false, false);
$outfiles.push($outfile);
}
catch(theError)
{
$error = theError;
$doc.closeDoc( {bNoSave : true} );
}
}
$error
For more information about scripting, refer to the documentation on the Enfocus website.