Script Debugger makes it easy to create, view, and check your code’s block structure. Blocks are a characteristic and pervasive feature of AppleScript: a tell
line is balanced by an end tell
line (forming a tell block), a repeat
line is balanced by an end repeat
line (forming a repeat block), and so forth, and blocks are nested inside each other to form the logic of your script.
Auto-closing is a text entry feature where, when you type Return in the opening line of a block, Script Debugger automatically generates the end
line of the block for you.
For example, if you type repeat
and press Return with auto-closing turned on, Script Debugger creates a corresponding end
line (which will compile to end repeat
), and positions the insertion point in between, ready for you to enter the content of the block. This works also for lines beginning with tell
, on
, script
, if
, try
, using
, considering
, and ignoring
. Script Debugger’s auto-closing feature is intelligent; if there is already a corresponding end
line, Script Debugger won’t create one.
You can turn on auto-closing in general, or use it on single occasions. To pick an auto-closing policy:
In the Editor preferences, check or uncheck “Auto-close AppleScript blocks (end tell, etc.).”
If checked, auto-closing is turned on in general. To turn auto-closing off on a single occasion, hold Control as you press Return at the end of a block-starting line.
If unchecked, auto-closing is turned off in general. To turn auto-closing on on a single occasion, hold Control as you press Return at the end of a block-starting line.
To select a block:
Choose Edit > Balance.
Or, choose Balance from the contextual menu.
Each time you choose Balance, Script Debugger selects the block enclosing the current selection. Thus, if you choose Balance repeatedly, you select the block enclosing the selection, then the block enclosing that block, then the block enclosing that block, and so on.
The Balance command selects other things besides blocks. If the initial selection is between a pair of delimiters, the delimiters and everything between them will be selected first. If the initial selection is within a comment, the comment will be selected first.
To clarify the block structure of your script visually, you can hover the mouse in the gutter (the area to the left of the script text). Script Debugger outlines the nested block structure, starting with the block to the right of the mouse, in successively darker shades of grey.
To turn on block structure shading:
When this feature is turned on, you can also select a block. To do so, click the mouse in the gutter when you see the nested block structure outlined. Click successively to select the next block outwards. This is similar to choosing Balance repeatedly.