ExtendScript to UXP
ExtendScript uses an older version of JavaScript (ES3). In contrast, UXP uses the V8 JavaScript engine which supports ES6; this has several notable features lacking in ExtendScript.
Not all the newer features of ES6 are used and/or supported in the UXP world, but as an ExtendScript developer, you should familiarize yourself with ECMAScript ES6 so you can understand the sample code.
This page goes over how ExtendScript can be rewritten in UXP script in simple steps.
For scripts,
- Save the file with
.idjs
extension. - Update the script for unsupported methods
Differences | ExtendScript | UXP | Applicable To |
---|---|---|---|
subscript operator [ ] Collection objects returned by InDesign like documents and paragraphs will not support subscript operator [ ] to access element at a particular index. The alternative is to use the method by name item()Objects like app.selection which is of type Array will support subscript operator. | Copied to your clipboard
| Copied to your clipboard
| All Versions |
Object.constructor.name Object.constructor.name which is a standard property in JS will return an empty string ("") for DOM objects. Alternatively, use the object.constructorName property. | Copied to your clipboard
| Copied to your clipboard
| Prior to v18.4 |
Comparison operators(== and ===) Comparison operators(== and ===) on InDesign DOM objects will always return false unless the objects have same reference. Instead use method equals() | Copied to your clipboard
| Copied to your clipboard
| All Versions |
instanceof The instanceof keyword isn't supported for InDesign DOM objects. Instead using object.constructorName property. | Copied to your clipboard
| Copied to your clipboard
| Prior to v18.4 |
Global object 'document' Global object 'document' is not supported now. Instead, use app.activeDocument | Copied to your clipboard
| Copied to your clipboard
| All Versions |
ActiveScript app.activeScript | app.activeScript returns the current running script as a file object on which you can access other properties. | app.activeScript returns the path of the current script as a string. No other properties can be accessed on app.activeScript | Prior to v18.4 |
Fetching the InDesign Server arguments passed to a script. | var myArg = app.scriptArgs.getValue("*argumentName*"); | let arguments = script.args; Learn More | v18.4 Onwards |