5. Scripting
A script is a sequence of commands. ZTerm scripts are stored in
TEXT files, which you can create with a text editor or most word
processors (you must save the file in a TEXT only format). A
script may be run from the “Run a Script” menu command, or by a macro
string or automatically run by the dialer when you connect to a
service. If a macro string starts with ® (Option-R) followed
by the name of a script file, that script file will be run when you
select that macro (from the Macro menu or with Command - number).
For example, I could set a macro label to “Read New” and set the macro
string to “®readnew.zts” and when I select Read New from the Macros
menu it would run the readnew.zts script file. You can stop a
running script by holding down the Command key and pressing the period
key. ZTerm looks in the ZTerm directory for script files.
It also looks in a folder called “ZTerm Scripts” in the ZTerm
directory. On Mac OSX, all these searches start in the users
Preferences folder (in the Library folder).
Logon Scripts
When ZTerm connects to a service, it will look for a text file with the
same name as the service with a “.zts” on the end. For GEnie, it
will look for a file called “GEnie.zts” in the ZTerm folder. If
it finds a file, it will run the script.
String constants can use any form of quote: "one", 'two',
“three”, ‘four’
Control characters in a string constant are specified with the ^
(carat) followed by the letter: "^M" is control-M, which is the
Return character. Other control characters:
^@ - NUL
^G - BELL
^H - Backspace
^I - Tab
^J - Line feed
^L - Form feed
^M - Carriage return
^Q - XON (resume data flow)
^S - XOFF (suspend data flow)
^[ - Escape
Built-in variables
$Account - string in the connection dialog
$Password - string in connection dialog
$Service - name of current service
$Phone - phone number for current service
$Date - in the short format
$Time - in hours, minutes and seconds (hh:mm:ss)
$hh_mm - time in hh_mm format (can be used to make a unique file name)
$Day, $dd - day of month ($dd has zero fill)
$mm - month
$year
$yy - low two digits of year
Script Commands
Beep
Beep <duration> -- if you are using the simple beep, you can give
a duration.
Beep 4 ticks
Close capture -- close the capture file.
Display <string(s)> -- display text in the terminal window
Display “Connected at ” $time
Hangup -- hangup the modem (same as the menu command)
Open capture <capture file name> -- start capturing data to a
file.
Open capture "GEnie.log"
Open capture “Internet.log.” $date “.” $hh_mm
(this would open a capture file named like
“Internet.log.9/29/94.22_50”)
Quit -- quit ZTerm
Send <string(s)>
Send “CIS^M” -- send the string (^M is a return)
Send $account “,” $password “^M” -- send multiple
strings
Send break <duration> -- send a break signal (default
duration is 1/4 second)
Send break 20 ticks -- break for
1/3 second
Wait <duration> -- pause a specified amount of time
Wait 2 seconds
Wait 40 ticks -- a tick on the Mac is 1/60
second (40 ticks is 2/3 second)
Wait for quiet <duration> -- wait for no incoming data for the
specified time.
Wait for quiet 4 seconds
Wait for prompt <string> -- check for the given string when data
stops. The word “for” is optional.
Wait for prompt “Username:”
Comments -- these three forms make the rest of the line a comment:
-- HyperCard style comments
# MPW style comments
; another comment character.
Example Script
# GEnie.zts - Simple logon script for GEnie
wait 2 seconds
# send hhh with short delay between them
send “h”
wait 10 ticks
send “h”
wait 10 ticks
send “h”
# wait for GEnie to prompt for your user ID
wait prompt "U#"
# send the account and password (from connection settings) with comma
between them
# and a return (^M) at the end.
send $account “,” $password “^M”
# send beep to wake up - you are logged in now
beep 5
display "Connected at " $time