PowerSwitch offers a comprehensive scripting environment. With limited scripting experience, a user can substantially extend Switch's capabilities and provide for interaction with third-party systems in new and powerful ways.
The various topics in this chapter describe the Switch scripting environment, including its capabilities for working with metadata.
In addition to Switch's own scripting environment, certain Switch configurators support executing JavaScript scripts inside the Adobe Creative Suite applications. These types of scripts are not discussed in this chapter; instead refer to JavaScript for applications.
Switch supports two types of scripting languages:
Operating system scripting languages: use the script execution mechanism provided by the operating system to support a platform-specific scripting language.
Internal scripting language: a cross-platform JavaScript subset implemented and executed inside Switch.
Operating system scripting is intended primarily for communicating with other applications or with operating systems services from within Switch. The supported scripting languages are:
AppleScript on Mac OS X.
VBScript on Microsoft Windows.
In each environment, a script object representing the Switch application provides access to key variables and functions, including the metadata context of the job being processed.
By definition, operating system scripts are platform-specific (i.e. not portable).
The Switch-internal scripting language JavaScript is intended primarily for working with variables and functions provided by Switch (rather than the operating system). A primary goal of the internal scripting language is to work with the contents of metadata fields associated with the jobs being processed.
Switch supports a substantial JavaScript subset (more precisely, it supports a subset of the ECMAScript 4.0 language), with extensions for:
Accessing key Switch variables and functions, including the metadata context of the job being processed.
Reading and writing plain text files.
Reading and writing XML files and performing XSLT transforms.
Executing a command line application.
Database access.
Webservices interaction.
JavaScript scripts have limited "external access". For example, there is no way to communicate with interactive applications, and there is no access to operating system services.
JavaScript scripts are cross-platform, i.e. they work without change on both Mac OS X and Microsoft Windows.
A script element is a flow element that encapsulates a script written in any of the supported scripting languages. The script implements an "entry point" function called by Switch for each job being processed through the flow element.
A script expression is a text string associated with a flow element property. To determine the value of the property, Switch evaluates the contents of the string as a JavaScript expression in the context of the job being processed. Only JavaScript is supported in script expressions.
The Switch scripting API (application programming interface) provides script elements and script expressions with access to information about the job being processed, including job ticket and metadata contents. Script expressions are limited to read-only access, while script elements can update the information.
A script that is to be associated with a script element consists of the following components:
Script declaration: an XML file that specifies information about the script, such as the name and data type of any properties (arguments) used by the script.
Script program: a plain text file that contains the script program itself, written in one of the supported scripting languages.
Script icon: optionally, an icon that is used to display the script element in the Switch flow designer.
These components are collected in a single file called a "script package" which is presented to the script element as a single entity. This also allows creating "fat" packages containing an implementation of the same functionality on multiple platforms.
A scripted plug-in is a script package that, when saved with the appropriate password and placed in the appropriate folder, behaves just like a tool or configurator built into Switch.
Scripted plug-ins are of no concern to regular Switch users. Enfocus may license selected third-party vendors to develop scripted plug-ins.
PowerSwitch includes a script development environment called SwitchScripter, installed as a separate application with the following major functions:
Create and edit Switch script packages and its components.
Emulate the Switch scripting API for testing purposes.
Setup specific input/output conditions for testing purposes.