Specifications

Script expressions
A script expression is a brief JavaScript program used to calculate the value of a flow element
property. Users can enter a script expression in a property editor dialog within PowerSwitch, that
is they do not need SwitchScripter. However, SwitchScripter provides some functions to help test
more complex script expressions; see Testing a script expression on page 343.
Selecting a scripting language
PowerSwitch supports three scripting languages (JavaScript, VBScript, AppleScript) as explained
in the Scripting reference on page 367.
In general, use JavaScript unless there is a good reason to select an operating system scripting
language (like VBScript or AppleScript). JavaScript scripts are cross-platform, that is, they work
without change on both Mac OS X and Microsoft Windows, and most of the PowerSwitch scripting
examples available on the web or from other users will be in JavaScript.
At the same time, 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.
If these features are necessary, use AppleScript or VBScript. If required, build a cross-platform
script package by including both an AppleScript and VBScript implementation.
If a script package contains more than one script program, PowerSwitch selects one of the
programs for execution by looking for them in this order:
The operating system scripting language for the platform on which Switch is running (that is,
AppleScript or VBScript).
JavaScript.
If neither of these are included, the script package cannot be executed.
Testing a script
SwitchScripter provides a simulated run-time environment for script testing purposes, avoiding
the need for moving back and forth between the Switch designer and SwitchScripter while
developing a script. The set of boundary conditions describing the test environment for a particular
script is called a fixture.
Fixture package
A fixture package is an archive file (with the ".sfixture" filename extension) that contains the
boundary conditions describing the environment for testing a script. Its contents can be configured
using the Fixture pane in SwitchScripter.
A fixture package is always stored alongside the script package (with the same filename but a
different extension). The fixture is not part of the definition of a script and may be removed
after the script has been tested.
A fixture package often contains references to test files. It just remembers the file paths, and
never includes the test files themselves. The test files are externally maintained by the script
writer/tester.
Testing a script
To test a script in SwitchScripter:
1. Create an initial version of your script as described in Writing a script on page 340.
2. Save the script package with an appropriate name in an appropriate location.
342
Enfocus Switch 10