Comments

AppleScript permits two kinds of comment : single-line comments and delimited comments. Everything including and after two successive hyphens on a line is a single-line comment. For example:

set a to 1 -- this a comment on the same line as a command
-- this a comment on a line by itself

The comment delimiters are (* and *). Everything between comment delimiters is a comment. Such a comment may span multiple lines. This code contains three stretches of text that are legally commented out with comment delimiters:

set a to 1 (* because we feel like it;
tomorrow we may not feel like setting a to 1 *)
(* in fact things could be very different tomorrow,
but I really can't speak to that issue just now *)
set b to 2 (* this seems a good idea too *)

A comment delimited with comment delimiters may not interrupt a command, nor precede a command on the same line. Neither of these lines will compile:

set a to (* because we feel like it *) 1
(* here's a good idea *) set a to 1

Comment delimiters attempt to be "intelligent." Comments may be nested, in which case the delimiters must match in pairs. Thanks to this rule, you can easily comment out a stretch of script that already contains some comments:

(* outer comment
(* inner comment *)
rest of outer comment *)

A rather weird side effect of this "intelligence" is that quotation marks and vertical bars inside comment delimiters must also match in pairs:

(* "this works fine" and so does |this| *)

If you remove one quotation mark or one vertical bar ...

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.