AppleScript_ The Definitive Guide - Matt Neuburg [13]
Script Editor
A script editor is an application such as Apple's own Script Editor (located in /Applications/AppleScript)—a general development environment where the user can create, edit, test, and run AppleScript code. A script editor application will almost certainly be central to your experience of AppleScript. Although you may use AppleScript code in other contexts, those contexts will generally provide no facilities for working on that code. Thus, no matter where you intend to use your code, you will first develop it in a script editor; if you wish to use it in some other context, you'll transfer it to that context from the script editor when you are satisfied that it is ready. If, using it in that other context, you discover there's a problem with it, you'll probably bring the code back into your script editor to test and improve it.
A script editor application will usually allow you to do things such as the following:
Edit a script in a convenient interface
Display a scriptable application's dictionary, which describes how to talk to it with AppleScript
Record user actions in AppleScript form, if a scriptable application is recordable
Compile a script, and display the compiled script in pretty-printed format (compilation is a necessary intermediate step between editing and running AppleScript code, and functions as an initial check on that code's validity)
Run the script's code
View the result, if any, of running the script's code
Save the script in any of the standard AppleScript formats
(Technical terms in this list are formally introduced in Chapter 3.)
There are three main candidates for use as a script editor: Apple's Script Editor , the freeware Smile, and the commercial Script Debugger. Each has its own advantages and peculiarities. You needn't feel confined to any single script editor; compiled scripts are a standard format, so any script editor can read the files of any other. (As of this writing, however, Smile still can't deal with bundle-formatted scripts.)
Warning
Using the AppleScript Utility application, located in /Applications/AppleScript, you can specify a default script editor application—the application that will open compiled script files when they are double-clicked from the Finder.
There are two hazards. First, the presence of Classic interferes somewhat; if anything but Script Editor is made the default editor, Script Editor files may try to open with the Classic Script Editor. Second, and more important, the distinction between files created by the different script editor applications is effectively destroyed; for example, if you use AppleScript Utility to set Script Editor as the default script editor, then a compiled script file subsequently created with Script Debugger may open in Script Editor when double-clicked.
Apple's Script Editor
Figure 2-1 shows a very short script being edited in Apple's Script Editor. The script has been compiled using the Compile button, which appears at the center of the toolbar at the top of the window; thus the script is pretty-printed with nice formatting and syntax coloring. The script has also been run, using the Run button in the toolbar; the result is shown in the lower half of the window. The script asks the Finder for the names of all mounted volumes; the response is a list of strings (see Chapter 13). Also shown is the Result History window, which logs the result of every execution of every script.
Figure 2-1. Apple's Script Editor
The lower pane of the script window consists of three tabs. The first tab, Description, lets the user enter a comment to be stored with the script. The second tab, the Result tab, is showing in Figure 2-1. The third tab, Event Log , records all outgoing commands and incoming replies