image

Block Structure

image

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.

Block Entry (Auto-Closing)

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:

Block Selection (Balance)

To select a block:

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.

Block Viewing and Selection

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.

image

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.



Delimiters
image