
CHAPTER 5: Interapplication Communication with Scripts Cross-DOM functions 167
Identifying applications
When calling external functions or exchanging messages, you must identify particular applications using
namespace specifiers. A specifier consists of a specific name string (such as
photoshop), and optional
additions that identify a particular release or locale version. Application specifiers are used occasionally in
other contexts as well. For details of the syntax, see “
Application and namespace specifiers” on page 191.
Regardless of which method you use to perform interapplication communication, you must place your
script in a location where the application you want to run it can see it. There are different locations for the
startup scripts of the applications themselves, and for scripts provided by developers.
Because all JavaScript-enabled applications look in the same locations for scripts to run, the scripts
themselves must be explicit about which application they are meant for. A script should check that all
applications it needs to communicate with are installed with the correct version, and that any other
applications that might be installed do not run the script. For details, see “
Scripting for specific
applications” on page 12.
Cross-DOM functions
The cross-DOM is a small application programming interface (API), which provides a set of functions that
are common across message-enabled applications. These include functions to open files, execute scripts,
and print files. For details of the function set, see the “
Cross-DOM API reference” on page 168.
You can access cross-DOM functions in any script by prefixing the function name with the namespace
specifier for the target application (see “
Namespace specifiers” on page 193). For example, a Photoshop
CS5 script can call
indesign.open(file) to open a file in Adobe InDesign
®
CS5.
The cross-DOM functions for each application are implemented in JavaScript. You can see the
implementation for each installed application by reading its associated startup script in the Adobe startup
folder. For example, Adobe Illustrator
®
CS5 defines illustrator.open() in the illustrator-14.jsx
startup script (14 is the version number of the installed application). See “
Startup folder locations” on
page 168.
Example code
The sample code distributed with the Adobe ExtendScript SDK includes these code examples that
specifically demonstrate the use of cross-DOM functions:
Application-specific exported functions
In addition to the required base cross-DOM functions, each message-enabled application can provide
application-specific functionality to all scripts through a simple syntax. You can access exported functions
in any script by prefixing the function name with the namespace specifier for the target application (see
“
Namespace specifiers” on page 193). For example, Photoshop CS5 exports the photomerge function, so
an Illustrator CS5 script can directly call
photoshop.photomerge(files).
The only difference between cross-DOM functions and the application-specific exported functions is that
all applications expose the same set of cross-DOM functions, whereas each application exposes its own set
Cross-DOM calls
OpenImageInPhotoshop.jsx
Shows how to send an image file to be opened in Photoshop.
Comentarios a estos manuales