Chapter 4: Scripts

PowerTerm Pro enables you to create scripts for automating tasks. Power Script Language is PowerTerm Pro's own programming language.

This chapter provides an overview of script commands and programming conventions used in Power Script Language.

This chapter also describes how to create, edit, run, save and activate scripts in PowerTerm Pro.

Each Power Script Language command is described in PowerTerm Pro's online help, which can be accessed by selecting Contents from the Help menu.

Script Overview

Power Script Language(PSL)

Using PowerTerm Pro Scripts

Using Visual Basic for Applications

Script Overview

You can use scripts to automate PowerTerm Pro tasks. Scripts are written in Power Script Language (PSL) and are saved with a .PSL extension.

For example, you can create a script to login to PowerTerm Pro, execute a file, display a message and so on. Scripts can be run upon startup or during a PowerTerm Pro session.

PSL Types

Simulation transmission to host commands: Enables you to communicate with the host. For example, the <send> command sends data to the host.

Standard programming commands: Enables you to use standard programming commands. For example, the <exec> command opens a program.

File handling commands: Enables you to work with files. For example, the <read> command reads from a file.

DDE commands: Enables you to use standard Microsoft Windows DDE mechanisms to communicate with other Windows applications.

PowerTerm-specific commands: Enables you to activate specific PowerTerm features. For example, the <map> command enables you to map a PC key to a host key.

Desktop interface commands: Enables you to manipulate components in the PowerTerm Pro window. For example, the <menu hide> command hides the PowerTerm Pro menu.

Power Script Language (PSL)

Power Script Language (PSL) is a special feature of PowerTerm Pro which provides commands for creating scripts. These scripts can be used to automate tasks. For example, you can create a script to login to PowerTerm Pro automatically. PSL is intended for users with programming skills.

PowerTerm Pro Sample Scripts describes the standard scripts used in PowerTerm Pro.

PSL Syntax, describes the syntax used to create PowerTerm Pro script.

PSL Data Types, describes common formats for data strings.

Variable Assignment, describes the syntax used to assign variables.

Activating Script Files from the Host, describes commands that activate a script file or script commands via special escape sequences.

DDE Commands, describes the function of DDE commands for both client and server applications.

PowerTerm Pro Sample Scripts

PowerTerm Pro provides several sample scripts designed for frequent tasks. The following table lists the sample scripts and their parameters:



Parameter Values


Port number

1 – 32.


Baud rate



Protocol type

none, xonxoff, hardware.


Host name

Specify the name of the host.


Service name

Specify the name of the service.


Node name

Specify the name of the CTERM node.

All parameters must be typed in lowercase letters.

Additional sample scripts are also included as part of PowerTerm Pro.

PSL Syntax

A command consists of one or more fields separated by spaces or tabs. The first field is the name of a command, which may be either a built-in command or a procedure consisting of a sequence of PSL commands. New-line characters are used as command separators, and semicolons may be used to separate commands on the same line. Each PSL command returns either a string result, or an empty string.

PSL has four additional syntactic constructs:

PSL commands must be entered in lower case.

Curly Braces

Curly braces are used to group complex arguments. They allow you to nest one argument inside another. If the first character of an argument is an open brace, then the argument is not terminated by white space. Instead, it is terminated by the matching close brace. The argument passed to the command consists of everything between the braces, with the enclosing braces stripped off.

For example:

host = {vms unix {aix hp sun} aos}

The variable host will receive one argument:

"vms unix {aix hp sun} aos".

This particular command will set the variable host to the specified string.

If an argument is enclosed in braces, then none of the other substitutions described below is made on the argument. One of the most common uses of braces is to specify a PSL sub-program as an argument to a PSL command.

Square Brackets

Square brackets are used to invoke command substitution. If an open bracket appears in an argument, then everything from the open bracket up to the matching close bracket is treated as a command and executed recursively by PSL. The result of the command is then substituted into the argument in place of the bracketed string.

For example, the format command:

msg = [format {Data is %s bytes long} 99]

invokes print-like formatting (from the C language) and returns the string "Data is 99 bytes long", which is then assigned to the variable msg.

Dollar Sign

The dollar sign is used for variable substitution. If the dollar sign appears in an argument, then the following characters are treated as a variable name; and the contents of the variable are substituted into the argument in place of the dollar sign and name.

For example:

num = 99

msg = [format {Data is %s bytes long} $num]

The result is the same as the single command in the previous example.

The following are examples of common functions for the dollar sign in Power Script Language:


The backslash character may be used to insert special characters into arguments, such as curly braces or nonprinting characters.

Such special characters include the following:

[ ] { } $ t b r m

\xFF will send the hex code FF (where F can be any hex character: 0-9, A-F).

For example:

send \x1B\[m

This command will send the three characters: escape, [ and m.

PSL Data Types

PSL uses only one type of data: strings. All commands, arguments to commands, results returned by commands and variable values are ASCII strings.

Although everything in PSL is a string, many commands expect their string arguments to have particular formats. There are three particularly common formats for strings:

A list is just a string containing one or more fields separated by white space, similar to a command. Curly braces may be used to enclose complex list elements. These complex list elements are often lists in their own right.

For example:

{vms unix {aix hp sun} aos}

This is a list with four elements, the third of which is a list with three elements.

PSL provides commands for a number of list-manipulation operations, such as creating lists, extracting elements and computing list lengths.

The second common form for a string is a numeric expression. PSL expressions have the same operators and rules of precedence as expressions in the C language.

The expr PSL command evaluates a string as an expression and returns the result (as a string, of course).

For example:

expr {($x < $y) || ($z != 0)}

elicits ''1'' if the numeric value of variable x is less than that of variable y, or if variable z is not zero; otherwise it returns "0''. Several other commands, such as if and for, expect one or more of their arguments to be expressions.

The third common interpretation of strings is as commands (or sequences of commands). Arguments of this form are used in PSL commands that implement control structures.

For example:

if {$x < $y} {

swap = $x

x = $y

y = $swap


The if command receives two arguments here, each of which is delimited by curly braces. If is a built-in command that evaluates its first argument as an expression; if the result is non-zero, it executes its second argument as a PSL command. This particular command swaps the values of the variables x and y if x is less than y.

PSL also allows users to define command procedures written in the PSL language. The proc built-in command is used to create a PSL procedures (PSLproc).

For example:

proc factorial x {

if {$x == 1} {return 1}

return [expr {$x * [factorial [expr $x - 1]]}]


This PSL command defines a recursive factorial procedure. The proc command takes three arguments: a name for the new PSLproc, a list of variable names (in this case the list has only a single element, x), and a PSL command that comprises the body of the PSLproc. After this proc command has been executed, factorial may be invoked just like any other PSL command.

For example:

factorial 4

returns the string "24''.

In addition to the commands already mentioned, PSL provides commands for manipulating strings (comparison, matching and printf/scanf-like C language operations), commands for manipulating files and file names. The built-in PSL commands provide a simple but complete programming language.

Variable Assignment


varName = value

varName[index] = value

Variable assignment is as follows: the variable varName is located on the left side of the expression and the value you want to assign to the variable is located on the right.

For example: B = 200

Two types of variables: Scalar and Array

A variable containing a single value is a scalar variable and the majority of the time fits ones needs. Other times, it is convenient to assign more than one related value to a single variable. You then can create an array variable that can contain a series of values. Array variables and scalar variables are declared in the same way, except that the declaration of an array variable uses parentheses [ ] following the variable name.

A variable’s scope is determined by where it is declared. When you declare a variable within a procedure, only code within that procedure can access or modify the value of that variable. It has local scope and is called a local variable. Differently, a global variable declared outside a procedure, is recognizable to all the procedures in your script. An exception to the rule governing local variables is when the global command has been invoked to declare varName as a global.

Activating Script Files from the Host

A host application may activate a script file or script commands via special escape sequences.

Escape Sequences for VT

Activating a script file called Script-Name:

ESCP$sScript-NameESC \

An example activating the message.psl script:


ESC is the ASCII 27 code.

Activating script commands called Script-Commands:

ESCP$tScript-CommandsESC \

An example activating the "message testing ; send end" commands:

ESCP$tmessage testing ; send endESC\

Escape Sequences for DG

Activating a script file called Script-Name:


ESC is the ASCII 30 code, 000 is the ASCII 0 code.

Activating script commands called Script-Commands:


DDE Commands

PowerTerm Pro enables you to use the standard Microsoft DDE mechanism to communicate with other Windows applications. PowerTerm Pro can be a DDE client application or a DDE server application.

The DDE server application waits for requests from DDE clients, and allows them to supply or receive information.

For example:

A spreadsheet DDE server will let clients get data from cells and put data into cells of a file.

As a DDE server, PowerTerm Pro uses the server name PTW with topic PSL. Any application can request it to execute commands and return the related return data.

A client application can access PowerTerm Pro with the dde execute command or the dde request command plus an item that can consist of multiple valid PSL commands separated with ";".

The single DDE server PSL command is:

dde return value

After a dde request command is executed, the PowerTerm Pro DDE server sends the value from the last dde return command executed in this request. If no dde return command is executed, it returns an empty answer.

Examples for PowerTerm Pro as a DDE server might be:

As a DDE client, PowerTerm Pro performs one of several dde operations, depending on the option. The legal options are:

dde initiate applicationName topicName

Connects to the applicationName DDE server with topicName. Returns a conversation id for use with successive dde commands.

dde execute convId command

Executes a server command. Returns an empty string.

dde request convId item

Returns an item from the server.

dde poke convId item value

Changes an item of the server to the new value. Returns an empty string.

dde terminate convId

Terminates a DDE conversation with the server.

dde returns

Returns a value according to the option.


1 Assigns three numbers on the emulation screen to array "cel"

for {i = 1} {$i < 4} {incr i} {

row = [expr $i + 3]

cel($i) = [screen-rect $row 10 $row 15]}

Initiates a DDE conversation with MicroSoft Excel file TEST.XLS.

conv = [dde initiate EXCEL TEST.XLS]

Pokes the three numbers to three cels in TEST.XLS.

for {i = 1} {$i < 4} {incr i} {dde poke $conv R1C$i $cel($i)}

Requests the sum of those numbers from a result cel in TEST.XLS.

sum = [dde request $conv "R2C1"]

Terminates the DDE conversation.

dde terminate $conv

Sends the result to the host application.

send $sum

2 Initiates a DDE conversation with another PowerTerm Pro which is connected to another computer. Reads information from the screen (of the other host) and sends it to its own host.

conv = [dde initiate PTW PSL-B]

data = [dde request $conv {

dde return [screen 10 1 15 80]}]

dde execute $conv{send joe}

See PowerTerm Pro's online help for an explanation of each DDE command. To access the online help for DDE commands, select Contents from the Help menu and click the Index tab. Type dde and click Display.