Meet Script Debugger’s debug mode! Debugging a script is like running it, except that in debug mode your script can pause in the middle.
Debugging is a separate mode; it’s a feature of your script. A script is either in debug mode or it isn’t. To turn on debug mode for a script:
Choose Script > Enable Debugging. If the menu item is checked, debug mode is on.
Or, click the Debugging button in the script window toolbar so that it says ON.
In debug mode, a script window’s appearance changes slightly:
NOTE: In the above screen shot, the toolbar icons are small and the names of the buttons have been removed, to save space.
In debug mode:
The Debugging button in the toolbar says ON.
The Step buttons (Trace, Step Over, Step Into, Step Out) and Breakpoints button appear in the toolbar (by default).
The gutter is wider (in order to accomodate breakpoints and code coverage markers), and displays pause arrows next to every line of the script where it’s possible to set a breakpoint.
In the Result & Variables tab, two additional panes appear: the call stack and the breakpoints inspector.
To turn off debug mode:
Choose Script > Enable Debugging. If the menu item is unchecked, debug mode is off.
Or, click the Debugging button in the script window toolbar so that it says OFF.
NOTE: You might have to stop your script (choose Script > Stop, or click Stop in the toolbar) before you can turn off debug mode. You can’t turn off debug mode if your script is running or paused.
Debug mode is a script feature; it is saved as part of a script file. It is also unique to Script Debugger. A script saved in debug mode is unusable except in Script Debugger. Therefore, when you’re finished debugging, you will probably want to save your script not in debug mode.
There is, however, one good reason for deliberately saving a script in debug mode and running it elsewhere — so that you can debug externally.
Debug mode gives your script (and you) many new powers.
Your script can pause in the middle of execution.
A major concern during debugging will be: where will your script pause? The answer involves chiefly the interplay between breakpoints and the stepping commands.
While paused, you can see (and alter) the values of your script’s variables, along with other AppleScript values, as they change during the course of execution.
You can see what code is executed and what choices your code makes. You can also run your code in slow motion, watching its path of execution.
You can observe how one handler calls another.
If your script involves driving a scriptable application’s interface, it may help you to work in the Mini Debugger, where you can interact with breakpoints and pauses in your script while keeping the scriptable application frontmost.
|