AppleScript_ The Definitive Guide - Matt Neuburg [53]
set x to 1
copy x + 1 to y
display dialog y
You can't have one complete command and then another complete command in the same line, but you can have one command nested inside another command, because most commands in AppleScript have a result (see "Result," later in this chapter), and most commands have at least one parameter, so the result from one command can often be used as the parameter to another command, in the same line. So, for example, in the second line of this code:
set x to 1
copy (display dialog x) to y
The only commands that can't be nested inside other commands in this way are a few special verbs implemented deep inside AppleScript, such as set and copy.
It is legal for a line to be completely blank. Extra whitespace (spaces, tab characters) is legal and will be ignored.
Line-Break Characters
In a decompiled script, the breaks between lines are all Macintosh return characters (\r, ASCII character 13). This is somewhat ironic, because in a present-day script editor application such as Script Editor or Script Debugger, when you press the Return key what you're entering is a Unix newline (\n, ASCII character 10). Thus the line-termination character goes into the compiler as a Unix line break and comes back out on decompilation as a Macintosh line break.
Indeed, in a script text file (or other text to be treated as AppleScript code) it doesn't matter whether the line-break character is the Macintosh line break, the Unix line break, or even the Windows line break (\r\n). If the code is valid, AppleScript will be able to compile it regardless (and all the breaks between lines of code will end up as Macintosh line breaks internally).
Line-Break Characters in Strings
It is legal to type a line break in a literal string (that is, between matched pairs of double quotes). This represents a line-break character within the string. For example:
set pep to "Manny
Moe
Jack"
The line-break character being inserted here is the line-break character you get when you press the Return key. What character that is depends upon the editing environment and the era. In the old days it was the Macintosh line break (\r); nowadays, as I mentioned already, it is the Unix line break (\n).
AppleScript also permits the representation of line-break characters through the return global property (see Chapter 16) and the "escaped" characters \r and \n (see "String" in Chapter 13). Thus your code can construct a string value containing a line-break character by using these representations. When you display such a string value, it will be shown (in most contexts) with a visible line break. For example:
set pep to "Manny" & return & "Moe"
return pep
The result (the value of pep) is displayed like this:
"Manny
Moe"
So too for a decompiled string literal containing an "escaped" line-break character. The change happens right within your script. If you type this:
set pep to "Manny\rMoe\nJack"
then when you compile (and decompile) you'll see this:
set pep to "Manny
Moe
Jack"
This behavior, by general agreement, is annoying, not least because (as the example illustrates) you have no way of knowing whether the line break in the decompiled representation is a Macintosh or a Unix line break. (Script Debugger solves this problem; it lets you view invisible characters in your script, and permits a literal string value to be displayed with "escaped" characters.)
Continuation Character
Long lines of code are inconvenient if your script editor application does not wrap them. In such an environment, if your code contains long lines and you want to be able to read them without scrolling horizontally, you need a way to break long lines. Because a line is a meaningful syntactic unit, you cannot do this merely by inserting a return character. Rather, you must also enter a continuation character.
Tip
The problem the continuation character solves is no longer much of a problem, though, because current