------------------------------------------------------------------------------- pcANYWHERE Script Language Quick Start Guide ------------------------------------------------------------------------------- Thank you for taking the time and interest in experimenting with The Norton pcANYWHERE Script Language. To better assist your script efforts, The Norton pcANYWHERE Technical Support Staff has created this document to help you gain a better understanding of how The Norton pcANYWHERE Script Language works and how to easily create scripts to automate your everyday communication needs. If you need assistance with scripting, feel free to call our technical support number at (310) 449-4900 and select option 5 between the hours of 7:00am and 5:00pm Pacific Standard Time, Monday through Friday. If you would like to fax us your script question(s) or code (only the portion that is not working correctly, not the whole script), feel free to send it to (310) 829-0247 anytime. When you fax, please be sure to detail your questions. Script faxes will be answered within 72 hours. Contents: -------- 1. Scripting - An Automation Concept. * What is a script? * What can a script do for me? * Scripts vs. Automated Procedures. 2. Creating A Script. * The basics. * Step by step to a connection. * Entering a script. 3. Something Worthwhile. * A real working example that does something. * How it works one step at a time. 4. Script Commands - Quick Reference =============================================================================== 1. Scripting - An Automation Concept * What is a script? A script is typically used to automate repetitive tasks that are usually done manually. Scripts can automate tasks so that operator intervention is not required and can be intermixed with manual operations to reduce the complexity of a task. To many computer users, scripts seem like a foreign language better left to the experts of that field. It involves programming, which tends to shun many users from exploring the possibility of putting this powerful feature to use. In fact, pcANYWHERE's script language is a programming language. Like Automated Procedures, they both execute a series of commands in some organized and logical order. The script language, unlike most programming languages, is interpreted, not compiled. This means that scripts generated in pcANYWHERE require pcANYWHERE in order to interpret the commands in the script, and will not function as a stand alone program. This limitation turns out to be an innovation which allows a user to enhance the power and flexibility of its "parent program". * What can a script do for me? Using the Norton pcANYWHERE, a wide variety of electronic information services can be utilized to enhance both your professional and personal life. As you continue to explore these services , you will find that you eventually settle into a routine. Example: Everyday, you call up service "A", and check your electronic mailbox. You also control pcANYWHERE/Host "B" which you access via a terminal server. Service "C" has an on-line encyclopedia which you frequently reference. For these situations, scripts could be utilized to streamline access to these services. A script could call service "A", enter whatever login sequence is required, navigate the appropriate menus to get to your mailbox, send your mail to the printer or disk file, and then disconnect. Connecting to host "B" requires that you first enter several access codes to route your call to the host. A script could enter this sequence for you, leaving you connected and in control of the host. Service "C" however, is different in that you will probably wish to look up different subjects each time you call, so the script in this case would start by prompting you for the subject you wish to inquire about, then automate the rest of the process. * Scripts vs. Automated Procedures Scripts are generally used for non-pcANYWHERE sessions or for pcANYWHERE sessions where an Automated Procedure is impractical, or incapable of performing a specific function. Automated procedures are generally used for unattended pcANYWHERE sessions requiring file transfers and/or simple DOS commands. [Note: Automated procedures ONLY work in pcANYWHERE sessions (i.e. pcANYWHERE Host and pcANYWHERE Remote).] 2. Creating A Script * The Basics First, you must fully understand what you want your script to do. Scripts make no assumptions, and only perform the instructions exactly as you have typed them in the script. A common error in creating scripts is assuming that the script will take care of "obvious" things, which are normally not thought of. To avoid errors when creating scripts, follow these three steps: 1) Do it manually, and carefully note each detail of the operation. 2) Pseudocode the operation. This means write it down, step by step, in plain English. This helps to formalize the thought process, and allows for an almost straightforward conversion to the final script. 3) Write the script. Each line of psuedocode should translate to one line (possibly two) of script code. Example: The purpose of this script will be to automate my login sequence to Compuserve (Compuserve is a world wide electronic communications service). First, I connected manually, and noted each detail of the operation: I dialed 555-1234 I waited for my screen to say "06CUI" (It says this when I call, it could be different for you.) I pressed [Enter] It said "Host Name:" I typed "COMPUSERVE" and pressed [Enter] It said "User ID:" I typed "1234,4321", and pressed [Enter] (This is my user ID, it is different for you.) It said "Password:" I typed "secret", and pressed [Enter] (This is my password, it is different for you.) And then I was connected. Now we have our psuedocode. Notice that each action taken in the script is in response to the prompts received from Compuserve. A frequent error when writing scripts is forgetting to tell the script what to look for before sending a response. Now let's turn the psuedocode into a script: ;This section prepares pcANYWHERE and the modem prior to making the connection set echo on ;Enable local character echo load config "Serial: Modem" ;Get communications parameters clear screen ;Clears the screen emulate ANSI ;Behave like an ANSI terminal ;This section contains the main body of the script, converted from pseudocode DIAL "555-1234" ;I dialed 555-1234 WAIT STRING "06CUI" ;I waited for my screen to say "06CUI" SEND STRING "^M" ;I pressed [Enter] WAIT STRING "Host Name:" ;It said "Host Name:" SEND LINE "COMPUSERVE" ;I typed "COMPUSERVE", and pressed [Enter] WAIT STRING "User ID:" ;It said "User ID:" SEND LINE "1234,4321" ;I typed "1234,4321", and pressed [Enter] WAIT STRING "Password:" ;It said "Password:" SEND LINE "secret" ;I typed "secret", and pressed [Enter] END TERMINAL ;End the script because I am connected * Step by step to a connection The first section of the script replaces the information which is normally contained on the Host Information screen in the Norton pcANYWHERE. The second line tells pcANYWHERE to display the incoming text. The third line loads all of the communications parameters, such as COM port, data rate, parity, etc., from the hardware configuration name specified between the quote marks (""). The fourth line clears the screen. The fifth line tells the script to function in same manner as an ANSI terminal would. The blank line in the above script is used as a separator, to make reading the script easier. Blank lines are ignored in the script language. Also, the semi-colon character (;) indicates that the rest of the line is just a comment. Lines eight through sixteen are the commands translated from the psuedocode above. Lastly, line seventeen goes into terminal operation which ends the script and allows you to interactively communicate with the host system (Compuserve, in this case). * Entering a script A script can be entered using your favorite text editor. This must be an ASCII text editor or one that will write plain ASCII text files. Save the script file with a name you choose, but use .SCR for the file extension. Then run pcANYWHERE/Remote, select UTILITIES, and then select PREPROCESS A SCRIPT. This will then prompt for the sub directory containing the script file. Enter the sub directory containing the script file, then select the script file from the list, and press [Enter]. This compiles the text file into the executable format that pcANYWHERE uses for its script files. Now the script can be executed. Simply select RUN SCRIPT from the main menu, select the directory the script file is in, and select the script file. 3. Something Worthwhile * A real working example that does something The example that follows will login to a pcANYWHERE host that is using any terminal emulation. You must have the same emulation set on the remote side in the Host Information screen. If any emulation other than pcANYWHERE emulation is used, it will allow selection of a file on the host machine and then transfer that file to the remote machine. If pcANYWHERE emulation is used, it will login and go into terminal mode. While in pcANYWHERE emulation, file transfers cannot be done via the script file and then return to the script. Also, the INPUT command will not work after connection while in pcANYWHERE emulation. Please see the following script: string d_load[79] ;set up a string variable to hold filename string host_name[79] ;string variable to hold host name string pass_word[79] ;variable for password integer emul ;variable for emulation integer infile ;for window name emul = 0 ;set default for PCAW emulation host_name = "My host" ;put YOUR host's name here between quotes pass_word = "hostpass^M" ;your password for this host you're calling clear screen ;Clears screen set echo on ;turn character echo on set cancel on ;Watch for ESC key to be pressed on cancel goto @ABORT ;If ESC pressed go to label @ABORT load hostinfo host_name ;load host info parameters type "Dialing Host^M" ;Type message on remote (^M=Enter key) wait 1 ;Pause for 1 second to see above message dial host host_name ;Read host info and dial this host on receive "press" goto @NONPCAW wait 3 @RESUME: send string "^M" ;send an ENTER wait string "password" 10 ;wait for string, timeout after 10sec send string pass_word ;send your password for this host wait string ">" 30 ;wait for the dos prompt's ">" sign if emul==0 then gosub @PDIR if emul==1 then gosub @NDIR wait silence 2 ;give time to display directory if emul==0 then end terminal window open infile 22 1 80 4 3 2 cursor position 2 2 type "Enter file you wish to download" cursor position 3 2 if emul==1 then gosub @NINFILE end terminal @NONPCAW: emul = 1 goto @RESUME @PDIR: send scancode "dir/w^M" ;get directory on host (pcANYWHERE emulation) return @NDIR: send string "dir/w^M" ;get directory on host (Non pcANYWHERE emulation) return @NINFILE: input d_load 79 ;get file name with max of 79 characters window close infile send string "cls^M" set echo off set quiet on send string "awsend " send string d_load send string " to remote^M" set quiet off set echo on receive file d_load ;put it in this path on the remote computer return @ABORT: ;Label for routine hang ;Hang up the phone end ;End the script 4. Script Commands - Quick Reference The pcANYWHERE manual has a reference to all the script commands but most users are new to scripting and want to know WHEN to use each of these commands. For that reason, the following reference will come in very handy. For additional information on any of the script commands, please consult the script chapter in the manual. answer..........Wait for a call beep............Make a beep sound on remote break...........Send a break signal to other modem cd..............Change directory on remote clear bol.......Clear characters from cursor back to beginning of that line clear bop.......Clear characters from cursor back to beginning of this page (screen) clear eol.......Clear characters from cursor to end of this line clear eop.......Clear characters from cursor to end of this page (screen) clear screen....Clear the entire screen close...........Close a file that was previously opened copy............Copy a file from one place to another on the remote system create..........Create a file on the remote that does not already exist cursor block....Make cursor look like a full rectangular block cursor down.....Move cursor down a number of lines cursor home.....Move cursor to the upper left corner of the screen cursor left.....Move cursor left a number of columns cursor line.....Make cursor look like a single underscore (line) cursor off......Turn off the display of the cursor cursor position.Set the cursor position to a row and column specified cursor restore..Restore cursor position to the place it was "SAVED" from cursor right....Move cursor right a number of columns cursor save.....Save the cursor position so you can "cursor restore" later cursor up.......Move cursor up a number of lines decrypt.........Decrypt string that was previously Encrypted del.............Delete a file on the remote delete char.....Delete a number of characters starting at cursor position delete line.....Delete a number of lines starting at current line dial host.......Dial a host dial number.....Dial a specific phone number dir.............Get a directory of remote machine emulate.........Specify emulation to use for current session encrypt.........Encrypt a string with a code (key string) end.............End current script end menu........End current script and go to pcANYWHERE menu end terminal....End current script and go into terminal mode exit............End script and go to DOS removing from memory find first......Find first file matching a file mask (i.e. *.txt) find next.......Find next file matching a file mask get file attr...Get the attributes for a specified file get file date...Get the date a file was created get file size...Get the size of a file get file time...Get the time a file was created get free disk...Find how much disk space is available on a drive get environment.Get the environment string associated with a variable gosub...........Call a subroutine for execution goto............Go to a specified label and continue execution at that point hang............Hang up the phone if..............Conditional processing - IF expression=true THEN command index...........Locate the position of one string within another insert char.....Insert count spaces at current cursor position insert line.....Insert count lines at current line position input...........Input data from keyboard until ENTER is pressed input key.......Input a single character from keyboard (not echoed) keyboard flush..Remove all keys from type-ahead buffer keyboard hit....Check to see if key is waiting for input let.............Used if destination variable is the same as a key word link............Link to another script file and end current script file load config.....Load a hardware configuration entry load hostinfo...Load a Host information entry load fkeys......Load a function key file load translation..Load a translation table file lower...........Convert a string to all lowercase characters md..............Make a directory on remote system on cancel.......Set command to execute for cancel entry (ESC) on disconnect...Set command to execute if disconnected on error........Set command to execute if an error occurs on receive......Set command to execute when receiving string on timeout......Set command to execute if time out occurs open............Open a file print file......Print a file to currently selected print device print line......Print a string & ENTER to currently selected print device print string....Print a string to currently selected print device printer.........Turn print on - if on, screen data is printed as its displayed rd..............Remove a directory on remote system read line.......Read n characters from a file or until end-of-line character read string.....Read n characters from a file into a string variable receive char....Receive one character from com port into a variable receive clear...Clear the receive buffer receive file....Receive a file using current protocol from the Host system receive line....Receive n characters from com port or until end-of-line char receive string..Receive n characters from com port into a string variable ren.............Rename a file on remote system reset...........Reset the terminal emulation to the default emulation return..........Return to the line after the calling GOSUB run.............Run a DOS program on the remote system screen restore..Restore a screen previously saved with SCREEN SAVE screen save.....Save a screen for later restoring with SCREEN RESTORE script..........Call another script then return to current script seek............Set file read/write pointer for subsequent read or write send char.......Send one character to com port send clear......Clear the send buffer send file.......Send a file to the Host system using current protocol send line.......Send a string and ENTER key to com port send scancode...Send string converted to scan codes to com port send string.....Send string to com port set attribute...Set screen color attributes set cancel......Set cancel checking on or off set chardelay...Set the default delay between each character sent set disconnect..Set disconnect checking on or off set dtr.........Set state of DTR signal set echo........Set echoing of characters during WAIT or RECEIVE on or off set file attr...Set the attributes of a file set file date...Set the date of a file set file size...Set the size of a file set file time...Set the time of a file set flow........Set flow control setting set ignorecase..Set checking for case when comparing strings to on or off set palette.....Set the screen palette attribute set parity......Set the parity value SET PORT........Set the desired com port. set protocol....Set the file transfer protocol set quiet.......Set screen display of certain commands on or off set record......Set recording mode on or off set rts.........Set the state of the RTS signal set speed.......Set the com port speed set timeout.....Set the default timeout value for WAIT and RECEIVE set translation.Set translation table usage to on or off strcat..........Concatenate a string onto the end of another string strcmp..........Compare two strings strlen..........Get the length of a string strset..........Fill a string variable with a value substr..........Extract part of one string and store into another terminal........Go to terminal mode for user interaction trim............Remove leading/trailing spaces and control codes from string type file.......Type a file on remote system to remote screen type line.......Type a string and ENTER key to screen type string.....Type a string to screen upper...........Convert a string to all uppercase characters wait carrier....Wait for a carrier signaling a connection wait receive....Wait for any character to be received from com port wait silence....Wait for n seconds of silence from com port wait string.....Wait for a string received from com port wait time.......Wait n seconds wait until......Wait until a specific time and date window close....Close a previously OPENed window window open.....Open a window on screen window select...Select a window on screen from a currently opened window write line......Write a string and ENTER key to a file write string....Write a string to a file =============================================================================== ------------------------------------------------------------------------------- File Transfer Demonstration Script / SDEMO1.SCR ------------------------------------------------------------------------------- ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ;: pcAnywhere File Transfer Demo Script :: ;: :: ;: You can put the name of this script file in AWREMOTE, :: ;: Host information list's 'Script to execute:' line. It :: ;: will run this script on connect to the host in ANSI :: ;: emulation. However, for this script to run properly, you :: ;: will need to use a Host information entry set for ANSI :: ;: terminal emulation at the Remote side, and a Caller :: ;: Information entry also configured for ANSI terminal :: ;: emulation at the Host side. Please replace the password :: ;: variable to the name of your choice, but keep the ^M for :: ;: the carriage return. Also replace the variable 'hostfile' :: ;: with the file name you wish to transfer from the host to :: ;: the remote. :: ;: :: ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ;::::::Variable Declaration:::::: STRING password[10] password="test^M" ;:::::::::::::::::::::::::::::::: ON CANCEL GOTO _cancel ;Sets error traping. SET CANCEL ON ;Turn error traping on. SET PROTOCOL XMODEM ;Sets transfer protocol to XMODEM. TYPE STRING "Waiting for host... " ;Displays message to remote user. WAIT STRING "..." ;Waits for text in quotes from host. WAIT 1 ;Waits 1 second. SEND STRING "^M" ;Sends carriage return. WAIT STRING "password:" ;Waits for text in quotes from host. WAIT 1 ;Waits 1 second. TYPE STRING "^MSending password..." ;Displays message to remote user. SEND STRING password ;Sends password variable. WAIT STRING ">" ;Waits for host prompt. WAIT 1 ;Waits 1 second. TYPE STRING "^MInitiating File Transfer" ;Displays message to remote user. SEND STRING "AWSEND hostfile TO REMOTE^M" ;Sends AWSEND routine to pcA host. WAIT 5 ;Waits 5 seconds. TYPE STRING "^MFile Transfer In Progress" ;Displays message to remote user. RECEIVE FILE hostfile ;Command to receive file on remote. TYPE STRING "^MEnd of File Transfer " ;Displays message to remote user. GOTO _end ;Jump to other location in script. _cancel: ;Script label. TYPE STRING "^MSession Cancelled. " ;Displays error message to remote. _end: ;Script label. HANG ;Disconnect line, end session. =============================================================================== ------------------------------------------------------------------------------- BBS Login Demonstration Script / SDEMO2.SCR ------------------------------------------------------------------------------- ;:::::::::::::Information:::::::::::::: ::::::::::::BBS Numbers:::::::::::: SDEMO2.SCR ;:This is a small script showing an :: :: 2400 (408) 973-9598 :: ;:example of how to log into the :: :: 9600 (408) 973-9834 :: ;:Symantec BBS automatically. :: :: :: ;:You must edit your own Host Info & :: :: :: ;:hardware configurations before this:: :: :: ;:setup can work. Please set your :: :: Once online, please use your :: ;:terminal emulation to ANSI in your :: :: hot key to access Terminal :: ;:host information for Sym BBS. :: :: Options. :: ;: :: :: :: ;:::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::::::::::: ;:::::::::VARIABLE DECLARATION::::::::: STRING passname[24] ;Declares the use of named string(s) STRING password[24] ;with character capacity bracketted. STRING cr[1] ; ;:::::::::::::::::::::::::::::::::::::: ;:::::::::::::SETUP SPECS:::::::::::::: KEYBOARD FLUSH ;flush all keystrokes in buffer. CURSOR OFF ;turns cursor off. ;:::::::::::Greeting Menu:::::::::::::: WINDOW OPEN greet1 5 1 80 15 3 2 CURSOR POSITION 2 24 TYPE "The Norton pcANYWHERE Script Demo" CURSOR POSITION 6 4 TYPE "Symantec and The Norton pcANYWHERE are trademarks of Symantec Corporation." CURSOR POSITION 7 6 TYPE "Other brands and products are trademarks of their respective holders." CURSOR POSITION 8 16 TYPE "(C) 1992 Symantec Corporation. All rights reserved." CURSOR POSITION 13 23 TYPE "Please press to continue....." HITKEY1: ;Lable. INPUT KEY cr[1] ;Waits for one character input for Keyboard. IF ($RESULT==13) GOTO KEYHIT1 ;Checks to see if input was a . If result is true continue to label KEYHIT1. BEEP ;Beep if incorrect. GOTO HITKEY1 ;Return to HITKEY1 because value was false. KEYHIT1: ;Lable. WINDOW CLOSE greet1 ;Close window GREET1, from above. ;::::::::::::Symantec BBS:::::::::::::: WINDOW OPEN option2 1 37 43 10 12 2 ;Opens new window call OPTION2. TYPE "Please enter the following information:" CURSOR POSITION 4 2 ;Changes cursor position within current window. TYPE "Type 'NEW' for new users & no password:";Screen information. CURSOR POSITION 6 2 ;Changes cursor position within current window. TYPE "Login Name: " ;Screen information. INPUT passname[24] ;Wait for keyboard input and . CURSOR POSITION 8 2 ;Changes cursor position within current window. TYPE "Password : " ;Screen information. INPUT password[24] ;Wait for keyboard input and . ;:::::::::Dialing Sequence::::::::::::: DIALOUT: ;Label WINDOW CLOSE option2 ;Close window GREET1, from above. LOAD CONFIG "COM 1: Telebit T1600 (Fixed)";Loads modem configuration. DIAL HOST "Symantec BBS / 38400" ;Dials host, based on Host Information in AWREMOTE. WAIT CARRIER ;Waits for Data Carrier Detect (DCD). RESET ;Refreshes screen, like in Sessions Options. WAIT 5 ;Waits for 5 seconds, gives time for host to send information. SEND LINE passname[24] ;Sends passname string with . IF (password=="") GOTO skip ;Checks password for input. SEND LINE password[24] ;Sends password string with . SKIP: ;Label. END TERMINAL ;Releases terminal mode to remote user. _______________________________________________________________________________ SYMANTEC has a number of other useful documents available through this BBS.