The Lie Of The Land

Kris Coppieters edited this page Nov 7, 2018 · 4 revisions

Stuff you need to understand

ExtendScript vs JavaScript

When automating a Creative Cloud app, you need to navigate two superficially similar environments.

One one hand, there is an ExtendScript interpreter which is deeply embedded into the Creative Cloud app (InDesign, Illustrator, Photoshop...)

One the other hand, there is a JavaScript interpreter which also running in conjunction with the Creative Cloud app.

The languages used by both these interpreters are very similar; ExtendScript is a dialect of JavaScript.

ExtendScript has features that JavaScript lacks (e.g. E4X) JavaScript has features that ExtendScript lacks

ExtendScript: Inward Facing

ExtendScript is 'inward facing': its main purpose in life is to manipulate the Creative Cloud document.

ExtendScript has some UI (User Interface) features, but they are very limited.

The ExtendScript engine is deeply integrated into the Creative Cloud app. It has access to a DOM (Document Object Model) that represents the documents managed by the app.

Each Creative Cloud app has a slightly different ExtendScript engine with a slightly different feature set.

Each Creative Cloud app has a very different ExtendScript DOM. For example, an InDesign document is very different than an Illustrator document. One has 'spreads', 'pages', 'paragraphs',... the other has 'artboards', 'layers',...

All of these engines are quite similar in many respects, but each has its own idiosyncrasies.

When you run an ExtendScript, it will run in the apps own process.

If you inspect the task list or process list on your computer when you run an ExtendScript you won't see any new process IDs being spun off to run the script.

Running ExtendScript is a synchronous process: the app is non-responsive while the ExtendScript runs.

JavaScript: Outward Facing

JavaScript is 'outward facing': its main purpose in life is to handle a UI (User Interface) in a browser-based environment.

It manages a 'standard' HTML/CSS/JavaScript browser DOM (Document Object Model)

This UI is then captured and shoehorned into a panel or dialog which in turn is managed by the app.

The app manages the 'frame' of the UI (e.g. as a panel, as a dialog...)

The UI shown in the 'frame' is managed by the JavaScript engine which runs in a detached process, separate from the app.

The JavaScript engine is based on the Chrome V8 engine and is not tightly integrated into the Creative Cloud apps.

When a JavaScript runs, it will run asynchronously; the Creative Cloud app and the JavaScript run in different processes, and running a JavaScript does not stop or hinder the app.

The JavaScript engine is not tightly integrated with the Creative Cloud app.

To interact with the app, a JavaScript will need to make an asynchronous call to the app, and receive a callback once the app finishes the call.

These calls can be either to the ExtendScript engine, or possibly to some native C++ code buried in some plug-in buried deep into the app.

Points of Confusion

In this complicated picture there is a lot of room for confusion:

  • There are two unrelated engines running a JavaScript dialect
  • One of the engines is asynchronous and detached from the app, the other is synchronous and embedded in the app
  • One of the engines is single-threading: while you run an ExtendScript the app becomes unresponsive. The other engine lives in a separate process, and only interacts with the app via asynchronous calls and callbacks.
  • One of the engines is inward facing, the other is outward facing
  • The UI handled by the JavaScript is framed into a UI frame or panel which is handled by the app.

This last point leads to situations where a JavaScript can call into ExtendScript, which in turn makes the app unresponsive until the script returns, which in turn freezes the 'frame' around the JavaScript UI.

So even though the JavaScript engine itself is in a separate process, the UI can still be 'frozen' because it is locked up when an ExtendScript script runs.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.