Steps in Writing a Script

Define what you want to accomplish and the steps required to accomplish the task. For example, suppose you have a list of CAS Registry Numbers (RN) and want to display their records on STN. What steps would you follow?

A.  Define the task

1. Log on to STN.
2. Enter the Registry file.
3. Display the record for the first RN.
4. Repeat step 3 until finished.
5. Log off STN.

B.  Translate the steps into Script Language statements that will accomplish the task.

1. Log on to STN.

The script could log on to STN, but it is often better to separate the logon task from the job the script performs. In this example, log on to STN as usual and then run the script.

2. Enter the Registry file.

The STN command to enter the Registry file is FILE REGISTRY. To use an STN command in a script, use the => (arrow prompt) statement:

=> FILE REGISTRY

3. Display the record for the first Registry Number.

To display a record on STN, use the DISPLAY command. Again we use the => statement:

=> DIS 50-00-0

4. Repeat step 3 until finished.

Add more DIS commands.

5. Log off STN.

End your STN session with the LOGOFF command, again using the => statement:

=> LOG Y

Creating a Script

To create a script, select Prepare Command File from the Query menu on the STN Express Main Menu. Click New in the Open Script dialog. This opens the STN Edit window with an Untitled text window inside it. Type the following script statements:

\* Display CAS RNs in the Registry file on STN.
=> FILE REGISTRY
=> DIS 50-00-0
=> DIS 7777-77-7
=> LOG Y

Saving the Script

To save the script file, select Save from the File menu. Type a name in the File name box and click Save. By default, the script file is saved to the User Scripts folder defined in General Preferences in the Setup menu (on the Main Menu Toolbar).

Do not use any name that exists in the Predefined Scripts folder unless you are replacing the functions of that script.

Checking the Script for Errors

To check the script for syntax errors, go to the Utilities menu in STN Edit and select Check Command File. If errors are found, STN Edit highlights appropriate script lines and displays a message at the bottom of the STN Edit window. To learn the nature of the error, move the mouse pointer over the highlighted part of a line. Correct the error, save the script, and check the script again until no errors are found.

Check Command File does not find all errors because some errors cannot be found until the script actually runs. It is not necessary to be logged on to an online host to use Check Command File.

Copyright © 2017 American Chemical Society. All Rights Reserved.