The Script window, shown in Figure 2-2 (from the OS 9 desktop) is where you edit and compile code. The other windows that are displayed and used by this program are dictionary windows, Event Log, and Result window (all these are discussed later in this chapter). The title bar of the window contains the name of the script next to a script icon that indicates which file type you saved it as (e.g., compiled script, applet). In Mac OS 9.1 and Mac OS X (i.e., AppleScript 1.5 and later), if you drag that icon to a disk folder the script will be moved to that folder.
All menu commands and windows attributed to Script Editor for OS 9 are replicated without any changes in OS X, except for the fact that the OS X Script Editor has been redesigned for the Aqua interface.
The following list describes the parts of the Script window:
Description field . The text area at the top of the script window is called the description field. This space assumes the role of a global comment area for the script. You can use this area to type in information about a script’s purpose, its properties, its functions, the scripting additions it may use, and any other helpful reminders to yourself or other script users. In addition, when creating a script to use an Apple Data Detector (ADD), use the description field to contain the type of detector that will be referenced in the script and other values. ADD is an intriguing Apple technology that allows you to run scripts that respond to contextual menu selections. Chapter 20, is devoted to ADD.
Record . Pressing this button or typing Command-D turns on Script Editor’s Apple-event recording capability. A cassette-tape icon will begin blinking in the upper left part of the computer screen on OS 9. Script Editor will only record Apple event code that originates from recordable apps, such as the Finder.
Stop . Clicking this button or typing Command-. stops recording. The Apple events that are recorded are converted from Apple event code into AppleScript terms and displayed in the script window. Only a few applications other than the Finder are recordable (see Chapter 1 for a description of recording a script). If you have turned on recording for a program and it is not recordable, then clicking the Stop button results in a blank script window.
Run . This button attempts to compile and run the script statements. Typing Command-R also executes this control. Any syntax errors in the script will cause an error dialog to be displayed.
Lower left pop-up menu. The pop-up menu button on the lower left of the script window (in Figure 2-2, where you see the label “AppleScript”) allows you to choose which scripting component will be used to compile and execute your script. This pop-up button identifies only installed scripting components (see Chapter 1 for a description of scripting components). AppleScript is selected by default in this button (it might be the only selection if this is the only scripting component you have installed on your machine).
Check Syntax
. Clicking this button compiles or
fails to compile the code in the script window. The first syntax
error this feature encounters is highlighted in the window. Check
Syntax does not run or save the script. If the syntax is okay, then
Script Editor will format the code by indenting it (such as indenting
the code inside of tell
statement blocks).