What does it mean to "comment" a script?

The ability to “comment” a script is extremely important in any programming language, and commenting is considered good form. Commenting a script simply allows you to enter lines which are not executed when the script is run.

This is useful for the following reasons:

  1. Commenting allows a script writer to add documentation (comments) to the script. This is very important with long, complex scripts, or in scripts which will be distributed to other users. A note here or there can go a long way toward explaining what a specific piece of code is supposed to do.

  2. Commenting is helpful in debugging a script. For instance, if there is a problem, it is sometimes easier to break the script down into smaller pieces to try to track the problem down. Instead of deleting script text, or copying and pasting script snippets into other windows, commenting can disable certain parts of the script without much effort.

There are two methods for commenting in AppleScript. One is simply to preceed the text to be commented with two hyphens (–), which disables everything else on that single line of script, like this:

-- set myName to "Steve"

The second method, best used for multiple lines of code, is to enclose it like this: (commented text here). For instance, to comment the second and third lines of this…

set myFirstName to "Steve"
set myLastName to "Jobs"
set myFullName to myFirstName & " " & myLastName
display dialog myFullName

I would do this:

set myFirstName to "Steve"
(* set myLastName to "Jobs" 
set myFullName to myFirstName & " " & myLastName 
display dialog myFullName *)

Or this, for better readability:

set myFirstName to "Steve"
(* 
set myLastName to "Jobs" 
set myFullName to myFirstName & " " & myLastName 
display dialog myFullName 
*)