Chapter 6. Syntactic Ground of Being

This chapter is about the basic facts of AppleScript language syntax. These are the facts you must know before you can read or write any AppleScript code at all.

Lines

AppleScript is a line-based language. There is no visible command terminator, such as a semicolon; a command ends with and is separated from the next command by a line break. For example:

set x to 1
copy x + 1 to y
display dialog y

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 (\r), the Unix line break (\n), or the Windows line break (\r\n). Presuming the code is valid, AppleScript will be able to compile it regardless; all line breaks are expressed as Macintosh line breaks on decompilation.

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 Literal 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"
display dialog pep

Exactly what line break character is represented in this way depends upon the editing environment. In the old Script Editor:

set pep to "Manny
Moe"
pep contains (ASCII character 13) -- true
pep contains (ASCII character 10) -- false

In the new Script Editor:

set pep to "Manny Moe" pep contains (ASCII character 13) -- ...

Get AppleScript: The Definitive Guide 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.