Section 14.1. First Line of Defense: The Compiler


14.1. First Line of Defense: The Compiler

When you click the Run button in Script Editor, the first thing that happens is your script gets compiled. That's AppleScript's way of finding typos, misplaced punctuation, and so on. If AppleScript finds an error, you'll see a dialog box like the one in Figure 14-1. Otherwise, your script proceeds to its regularly scheduled commands.

Unfortunately, AppleScript compiler errors are notoriously hard to decipher. Unless you have a Ph.D. in programmer-ese, therefore, Table 14-1 will be of great assistance in your compiling adventures.

Table 14-1. Common AppleScript compiler errors

Error message

Code that would produce it

What's the problem?

A class name can't go after this identifier.

tel application "iCal"     activate end tell

Misspelling a command

Expected end of line but found ".

tell aplcaton "iCal"     activate end tell

Misspelling the word before a string

Where is iCa?

tell application "iCa"     activate end tell

Misspelling a program's name

Expected """ but found end of script.

tell application "iCal     activate end tell

Missing a quotation mark

Expected end of line but found identifier.

tell application "iCal"     activat e end tell

Space in the middle of a command

Expected end of line, etc. but found "tell".

tell application "iCal"     activate en tell

Misspelling the first part of an end statement

Expected "tell", etc. but found "if".

tell application "iCal"     activate end if

Mismatch between the kind of statement (tell) and the end of the statement (if)


Of course, the compiler can only catch superficial errors (typos, missing quotations marks, and so on). If you misprogram your scriptbut spell everything correctlythe compiler won't catch your mistakes. That's why it's important to track what your scripts are doing as well; that way, you can narrow any problems down to a few lines of code.

Figure 14-1. A compiler error. After you click OK, Script Editor jumps to the line in your script that has the error, so you can fix it.




AppleScript. The Missing Manual
AppleScript: The Missing Manual
ISBN: 0596008503
EAN: 2147483647
Year: 2003
Pages: 150

Similar book on Amazon

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