Chapter 5. Syntactic Ground of Being

This chapter is about the basic facts of AppleScript language syntax. These are the facts you must be aware of 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

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 ...

Get AppleScript: The Definitive Guide, 2nd Edition 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.