Debugging with Event Log and Result Windows

Script Editor has two minimal debugging tools on OS 9 and OS X: Event Log and Result windows.

Event Log

You can open the Event Log by typing Command-E or by choosing it under Script Editor’s Controls menu. If you select the Show Events and Show Event Results checkboxes in the Event Log window, then running the current script will display the result of each Apple event after a (—>) symbol (Chapter 1 discusses Apple events). You can use Event Log to follow along with a program and make sure that the results of each operation are what you expect them to be. Figure 2-8 shows the Event Log window in OS 9.

Event Log window
Figure 2-8. Event Log window

You can use the log keyword in your program and uncheck Show Events and Show Event Results if you just want to track the value of a certain variable in your program. For example, the log window depicted in Figure 2-8 is associated with the program in Example 2-2 (an OS 9 applet).

Example 2-2. Using the log Keyword in Event Log
tell application "Finder"
   set todayFiles to 
   set filecount to 
   log (filecount)
end tell

If you unchecked the checkboxes in Event Log, then the Event Log window will only show the result of the log (filecount) statement bracketed by AppleScript comment symbols (* *). In this case, the result of the log (filecount) statement is the value of the filecount variable. If you had 30 folders ...

Get AppleScript in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.