Joel Gould Vocola Information Pages
by Rick Mohr (last modified March 24, 2001)

 Introduction
 Tutorial
    Keystroke Commands
->     Alternatives and References
    Defining Variable Terms
    Substitutions
    Function Calls
    Optional Words
 Using Vocola
 Download and Install
 Known Problems
 My R S I Story
 

Alternatives and References

Alternatives And References Sometimes you will want to create a group of similar commands.  Instead of creating a separate command for each, you can often write a single command which works for the whole group.

For example, you might want to be able to say either "Switch View" or "Next View" to switch between views in an application:
 
 Vocola: (Switch | Next) View = {Ctrl+Tab}; 
 Say: Switch View Sent: {Ctrl+Tab}
 Say: Next View Sent: {Ctrl+Tab}

Here the alternative term (Switch | Next) allows you to say either.

In many cases you want the actions invoked by a command to depend on which alternative was spoken.  For example, you might want to move the cursor in one of four directions by saying "Move Left", "Move Down", etc.:
 
 Vocola: Move (Left | Right | Up | Down) = { $1 }; 
 Say: Move Left Sent: {Left} 
 Say: Move Down Sent: {Down} 

Here the "$1" specifies that the first variable term should be substituted.  So, when you say "Move Left" the value of the first variable term is "Left" and the keystrokes "{Left}" are sent.
 
This example contains three actions -- the keystroke "{", the reference "$1", and the keystroke "}".  We will see later that a reference may actually expand to a series of actions, but in this example the reference expands to a single keystroke sequence such as "Left". When the three actions are combined, the result is the single keystroke sequence "{Left}".

Often you will want to specify a range of numbers as alternatives in a command.  This can be specified concisely in Vocola, as in the following example:
 
 Vocola: Move Down 1..10 = "{Down " $1 }; 
 Say: Move Down 1 Sent: {Down 1}
 Say: Move Down 6 Sent: {Down 6}

Here the syntax "1..10" is shorthand for "(1|2|3|4|5|6|7|8|9|10)". On the right hand side we substitute the spoken number (e.g. "6") to construct the syntax for a repeated keystroke ("{Down 6}") and we have a command which moves the cursor down a specified number of lines.

In real life it's very useful to control the arrow keys by saying simply "1 Down", "3 Left", "6 Up", etc. Here's how to write it in Vocola:
 
 Vocola: 1..40 (Left | Right | Up | Down) = { $2 " " $1 }; 
 Say: 3 Left  Sent: {Left 3}
 Say: 12 Down  Sent: {Down 12}

This command has two variable terms. On the right-hand side the second term (which direction to move) is substituted first and the first term (how many times) is substituted second, to create the necessary keystroke syntax. The quoted space character causes the space keystroke to appear between the two resolved references.
 

This web page (http://people.ne.mediaone.net/rmohr/Vocola/AlternativesAndReferences.html) was last modified on March 24, 2001. The contents of this page are (c) Copyright 2000-2001 by Rick Mohr. All Rights Reserved. See Copyright Information for more details.