Introducing Script Editor


For creating and editing AppleScript scripts, you can use the Script Editor application included with Mac OS X. Script Editor can also run scripts, and it can make scripts into self-contained applications that run when you double-click them in the Finder. Script Editor is normally located in the AppleScript in the Applications folder.

Tip

If you end up doing a lot of scripting, you may want to replace Script Editor with a more capable script development application, such as or Script Debugger from Late Night Software (www.latenightsw.com). Make sure you get a version made for Mac OS X.

Scriptable applications and environments

The scripts you create with Script Editor can control any scriptable application. A prime example of a scriptable application is the Finder. Other scriptable applications included with Mac OS X include Apple System Profiler, ColorSync Scripting, Internet Connect, iCal, iChat, iPhoto, iSync, iTunes, Internet Explorer, Mail, Print Center, QuickTime Player, Sherlock, StuffIt Expander, Terminal, TextEdit, and URL Access Scripting. Interestingly enough, even the Script Editor is scriptable. In addition, many Mac OS X applications not made by Apple are scriptable.

Plenty of Classic applications are also scriptable. Although a Classic version of Script Editor is included with Mac OS 9, you can use the Mac OS X version of Script Editor to make scripts for the Classic environment as well as for Mac OS X.

Looking at a script window

When you open Script Editor, an empty script window appears. Each script window can contain one script. The top part of the script window is the script editing area, where you type and edit the text of the script just as you type and edit in any text editing application. The bottom part of the window is the script description area. You use this area to type a description of what the script does. Figure 23-1 shows an empty script window.

click to expand
Figure 23-1: A new script window appears when Script Editor opens.

Tip

You can change the default size of a new script window. First, make the script window the size you want and then choose Save as Default from the Window menu in Script Editor.

The tool bar of a script window has four buttons. You find out more about each of them in later sections, but the following list summarizes their functions:

  • Record. AppleScript goes into recording mode and creates script statements corresponding to your actions in applications that support script recording. You can also press z-D to start recording. You cannot record scripts for every scriptable application because software developers must do more work to make an application recordable than to make it scriptable. You can find out whether an application is recordable by trying to record some actions in it.

  • Stop. Takes AppleScript out of recording mode or stops a script that is running, depending on which action is relevant at the time. Pressing z-period (.) on the keyboard is the same as clicking Stop.

  • Run. Starts running the script that is displayed in the script-editing area. You also can press z-R to run the script.

    Before running the script, Script Editor scans the script to see if you changed any part of it since you last ran it or checked its syntax (as described next). If the script has changed, Script Editor checks the script’s syntax.

  • Compile. Checks for errors in the script, such as incorrect punctuation or missing parts of commands. If any errors turn up, Script Editor highlights the error and displays a dialog explaining the problem. Script Editor also formats the text to make keywords stand out and the structure of the script more apparent. Script Editor may even change the text, but the changes do not affect the meaning of the script.

    If the script’s syntax is correct, Script Editor tells AppleScript to compile the script, which means it converts the text of the script into codes. These codes are what Apple event messages actually contain and what applications understand. You don’t usually see these codes in Script Editor, because AppleScript translates them into words for the enlightenment of human beings.

Note

If you use the Classic version of Script Editor to run or check the syntax of a script that controls an application that isn’t open, the script may fail while waiting for the application to open. Wait until the needed application opens and then try the script again.




Mac OS X Bible, Panther Edition
Mac OS X Bible, Panther Edition
ISBN: 0764543997
EAN: 2147483647
Year: 2003
Pages: 290

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net