AppleScript Dynamic Debugging
Volume Number: 13
Issue Number: 8
Column Tag: Scripting
Dynamic Debugging of AppleScript
by Cal Simone, Main Event
Special debugging techniques for a special language
Talking About AppleScript
AppleScript is the scripting language of the MacOS. Much of AppleScript's syntax
resembles that of a human language -- in many cases, you can write grammatically
correct, imperative sentences to control your computer. But the experience of
debugging AppleScript scripts can differ significantly from that of debugging a regular
application.
In this article, I'll discuss:
• Debugging programs in traditional programming languages.
• What's different about debugging AppleScript.
• What comprises dynamic debugging
• How to debug an AppleScript script using these techniques.
• Special topics, such as debugging handlers, messages that originate from
outside a script application, and AppleScript CGIs.
• Some extra AppleScript debugging goodies.
Lather, Rinse, and Repeat (The Traditional
Debugging Cycle)
In most traditional programming languages the debugging process goes something like
this:
• Type, copy, and paste in an editor to create and modify your source code.
• Compile your program into executable 68000 or PowerPC machine code.
• Run your program.
• Discover a bug and figure out the problem.
• Repeat this cycle until there are no more bugs.
For traditional programming languages, this edit-compile-run-debug cycle is
normally fine. When you start your C program over each time to run it, you'll usually
start over executing your program with a clean slate -- everything's gone when you
start anew.
Debugging in AppleScript
AppleScript differs from most traditional programming languages in a number of
ways:
• AppleScript has a natural-language syntax. It often consists of
human-readable constructs such as tell the application "WordPerfect" to
print the second window. Because of this human-readability factor,
AppleScript's audience includes more than hard-core software developers.
Programmers possess the abilities to think logically, to pay very close
attention to detail, and to work adeptly with abstract symbolic notation. But a
much wider variety of experience and technical skills are found among
scripters -- in fact, many people who write in AppleScript can't or don't
program in regular programming languages; a great many don't even think of
themselves as programmers. While they can think logically and do well with
detail, they aren't comfortable translating more cryptic symbolic notation
into a set of instructions. So, in addition to software developers, among
scripters we find power users, system administrators, and the guy or gal who
helps others in their department set up scripts to make their work a little
easier. (Even the nomenclature is different in the AppleScript world -- we
see terms such as "command", "handler", and "message", instead of words like
"statement", "function", and "code".)
• AppleScript does interapplication communication. A great deal of
AppleScript's power is drawn by leveraging other existing applications,
known in the AppleScript world as target applications. A single line of
AppleScript can send an interapplication message (an Apple event) to a target