Using the Scripter

Created by Stefan Rennick Egglestone
Last update by Stefan Rennick Egglestone 2006-06-29

Overview
Getting started
The Scripter window
Constructing a simple example
Understanding how the script works
Advanced features of the Scripter

Overview

The Scripter is an experimental application that allows a user to manipulate ECT components by writing scripts (rather than by specifying component configurations graphically through the Graph Editor). Scripts are written in a version of the BeanShell language which has had extra feature added to make it usable in this situation. The Scripter application provides functionality which can assist a user in the development of a script, and to browse details of a script which is currently being executed.

Scripts developed and used in the scripter application have access to any components that are available through the Graph Editor. As such, they are allowed to access and modify any properties defined by such components, thereby allowing scripts to manipulate any hardware devices associated with a component. It is also possible to develop scripts that can perform tasks when the values of any monitored properties change, and it is hoped that the combination of these simple facilities, along with the general purpose scripting facilities provided by BeanShell, will provide sufficient flexibility to specify many different ubicomp installations.

In fact, it may well be the case that specifications of complex behaviours involving large numbers of components may well be simpler through the use of scripting than through the use of the graph editor, as complex graphs can become difficult to understand, maintain and expand.

The rest of this section describes how to get started with the Scripter, and describes how to construct a simple installation using software-only components. It is hoped that this will provide sufficient information to users who wish to construct more complex installations. The section assumes that the reader is familiar with the ECT graph editor, and associated technologies. You should follow the Learning to use ECT tutorial if this is not the case (and also the ECT Overview if you are not familiar with the ECT system.

Getting started

To get started with the Scripter, you will need to have downloaded and unzipped the latest full release of ECT (rather than the cut-down release). See the Getting Started guide for information on how to do this. Then follow this procedure (assumes that you are working on a windows machine):

  1. Follow Method 2 in the Getting Started guide to launch the graph editor through a mechanism which is suitable for experimental pieces of software such as the Scripter.
  2. locate the install directory (with the ect and java directories in your unzipped ECT installation and double click on the runScripter.bat file

You should now have 4 seperate graphical windows, labelled:

Of these, the last three windows are important to the scripter. You should use the Capability Browser to create instances of any components that you want to control through a script. These components will then appear on the Graph Component Editor. The Scripter window is used to write and test scripts, and any connections created by a script will also appear in the Graph Component Editor.

The Scripter window

The scripter window will look something like figure 1 below:


Figure 1

The white text area on this window contains an example script (starting inputs:...). The three buttons above this text area are used to start the execution of this script (left button), stop the execution of a running script (middle button) and to browse any errors produced by a script (right button). The current example script does not do anything useful without the creation of any components to control, so you shouldn't run it. Instead, the example section of this document will demonstrate how to build a simple example to show how the Scripter works.

Constructing a simple example

  1. Create an instance of the TestingTextFieldInput component through the capability browser.
  2. In the graph component editor, select this new component, drag it down to the editor pane, then right click on the top section of the component in the editor pane, and select the "Settings" option on the pop-up menu.
  3. Using the Component Settings dialog that appears, change the name of the component to something shorter (eg TextInput), then close the dialog.
  4. Using the same procedure, create an instance of the TestingTextFieldOutput, and change its name to something shorter (eg TextOutput)
  5. Now delete the existing example script in the Scripter window, and replace it with the following:
    inputs:
      TextInput.value as String in
    outputs:
      TextOutput.value as String out
    state:
    status:
    on in:
      out = in;
    
  6. Click the run button on the scripter window. A message should appear on the bottom of the window indicating that the script is now running
  7. associated with the TestingTextFieldInput component should be a window containing a text input field, and with the TestingTextFieldOutput component should be a window which can output text. Locate these windows, type some text into the input field and press return. If the script is running properly, you should find that the text is copied by the script to the output window, without you having to add an edge between these components in the graph editor.

Understanding how the script works

This script consists of five seperate sections, labelled inputs,outputs,state,status and on in, although the state and status sections are empty. This section describes the function of the inputs, outputs and on in sections.

inputs section

This section is used to define the component properties that are to be used as inputs to the script. In the example script above, this section only has one line:

inputs:
  TextInput.value as String in

This line means that property value on a component named TextInput will be considered as an input to the script, and that this property will be referable to using the variable in throughout the rest of the script.

Users can add as many different properties as they wish to the inputs section, providing that each is given a different variable name.

outputs section

This section is used to define the component properties to which this script will output values, and in the example script above, this section also only has one line:

outputs:
  TextOutput.value as String out

In this case, this means that property value of component TextOutput will be used as an output of the script, and will be referable to through the variable out

on in section

This section specified what actions should occur when the value in variable in changes. Since this variable refers to property value of the component named TextInput, then this allows a user to specify an action to be performed when this property changes. In this case, the action that is to be performed is to set the variable out to the value of the variable in:

on in:
  out = in;

Since variable out refers to property value of the component named TextOutput, then this has the effect of setting this property to the value of the value property of the TextInput component.

Note that the text in this section, ie the line that says out = in; is called a scriptlet. Scriptlets can consist of multiple lines of BeanShell code, but please ensure that these lines are seperated by a semi-colon, eg

on in:
  in = in/2;
  out = in;

How do scripts appear in the Graph Editor

After having started the script running, take a look at the graph editor window, which might look something like figure 2 below:


Figure 2

The component labelled ScripterGUI.main has been created by the Scripter application, and you can see that it has properties which correspond to variables defined in the input and output sections of the script, as described above. These properties are connected to the properties of other components from which they take input, and to which they provide output, and these connections have also been created automatically by the Scripter application.

Advanced features of the Scripter

The Scripter application provides some features that can assist you in the development and testing of scripts. Some of these are described below:

Adding a new input/output to a script

Rather than having to add line such as
TextInput.value as String in

to a script by directly typing it, the Scripter provides graphical features that can assist. Move your cursor to the place where you want a new line to be added, and select either Input... or Output... from the Insert menu. You will then be shown a dialog that looks something like figure 3 below:


Figure 3

This displays a selection of lines that might be added. Click on one, and click OK, and this line will be added at the position where your cursor is. If you add any components to your graph whilst viewing this dialog, then you might have to click Refresh for any properties you have to appear in the dialog.

Viewing script variables

Whilst the script is running, you can view the status of any variables that it defines. To do this, select the Variables option from the View menu, which will launch a dialog looking something like figure 4 below:


Figure 4

In this case, this indicates that the script has two variables named in and out, gives their values, indicates that they are linked to a component (ie their Link Status is given as OK) and gives the name of the property of the component to which they are linked.