Run & Debug
After a script has been created, it needs to be tested to ensure that it behaves as expected. The first step is to run the script. Unlike other scripting tools, Script Debugger can run multiple scripts simultaneously. At the end of a successful script execution, AppleScript returns a result that helps you to understand what the script has done and what affect the script has had on its target applications. When a script fails to execute because of an error, AppleScript also returns a result, which every scripting tool displays. Only Script Debugger provides control over the script’s execution and displays detailed results.
(click to enlarge images)
Execution control makes determining precisely what’s occurring in a script easier as it’s possible to see intermediate results, not just the last one. With Script Debugger’s fine-grained control, the state of the script inside of script structures such as repeat loops and handlers becomes accessible, a key tool in writing scripts that work. To gain access to the advanced debugging features, simply switch the script’s language from AppleScript to AppleScript Debugger X. Script Debugger then enables the use of breakpoints—a feature not available with any other scripting tool.
Other tools require special instructions in the script itself to handle problems, control execution and report intermediate results (because they only display the last result). Since Script Debugger maintains complete information about the script’s state and displays that information any time that the script pauses or stops, the ability to stop the script at any point is a powerful component in script development. The key to successful scripting is knowing what the script and its target are doing at critical points.
See Into Scripts
Far beyond simply running scripts, controlling execution and viewing script results, the depth and breadth of the information that Script Debugger displays far exceeds any other tool. View and explore what an expression or script returns in the greatest detail possible—the results displayed can take the form of the Explorer, a preview of an image or movie, and much more. In addition, all global and local variables and properties of the script appear in the result. These results can be explored in detail in a similar fashion to the Explorer. The rich information that Script Debugger maintains appears in numerous places in scripts, from tooltips displaying expression results in the editor and descriptions of elements and properties to definitions of data.
While a script runs, tell at a glance what’s happening within it because items in the Explorer and Results Drawer that have changed, appear in red. Script Debugger also shows far more than just the script’s result—everything from which handler is executing to detailed information on the performance of the script. See which lines have executed and which ones have not with Script Debugger’s visual code coverage indication. Every line that did execute will have a blue background and a mark in the scroll bar, making it easy to jump directly to parts of the script by clicking in the scroll bar. Script Debugger provides other tools for understanding what a script does, from the ability to enter any expression in the Expressions Pane to the Tell Context Inspector (which shows only the most relevant dictionary information about what’s selected in the editor).
Control Script Execution
With Script Debugger, ensure that scripts operate as expected—from helping create the script correctly in the first place to providing everything needed to quickly identify the issues and to fix them. If an error does occur, Script Debugger makes determining the cause quick and easy—the offending code is highlighted and the error sheet displays the error message and error code. Begin debugging immediately without having to set a breakpoint and run the script again when using the new Break On Exceptions option. It’s as if a breakpoint had been set there before running the script. That’s only the beginning of what Script Debugger, the only AppleScript debugger available, offers scripters.
Of course, no other tool provides the ability to control script execution with breakpoints, tracing and break on exception behavior. When a script halts, whether it’s from clicking the Pause button, reaching a breakpoint or because of an error, Script Debugger displays all the information that the script contains. Only Script Debugger offers step-by-step execution of scripts to see exactly what happens at every point, view the results, alter values as needed, and continue. Control the execution with breakpoints and tracing. Use breakpoints and exceptions to view only the parts of the script where the problems arise. Understand the details of every handler, loop, and other control mechanisms until assured that those parts are working properly, then skip them with Step Over, Step Out and Step In. Tracing executes line-by-line without manually stepping through or setting breakpoints. It runs the script slowly enough that all the changes to every attribute and value appear at every step.
Pinpoint Script Errors
Since an error stops the script and Script Debugger tracks all the variables and their values up to that point, it’s easy to discover what went wrong. Script Debugger presents a complete picture of what’s happening as your script runs and helps find the shortest path to a solution. The error reporting integrates tightly with the Dictionary and Editor and includes, when possible, Viewers for the attributes and values in action when the error occurred or at chosen points in the script. Examine the cause of an error in depth by exploring the Error Sheet—Script Debugger displays the cause of the error, and the Result Pane displays the state of the script immediately preceding the error.
In addition to displaying detailed information about the error, Script Debugger makes it easier than ever to navigate the script after the error. Every line that successfully executed has a blue background, making it easy to identify the location of an error and to return there after viewing other parts of the script. Script Debugger highlights the line containing the error, selects the code causing the error, places a badge next to the line which will recall the error sheet when clicked (in Script Debugger it’s not necessary to run the script again to view the details of the error), and places a special tick mark in the scroll bar. Even Script Debugger’s Apple Event Log provides much more than simply displaying the events. It’s even possible to control the script’s execution from there. Know which Apple Events occurred and jump to the line in the script that generated any entry in the log.