Script Debugger 4.0
When Apple was touting Automator as part of the 10.4 Tiger upgrade, many people began to wonder whether AppleScript was needed at all. Of course, now that we’ve seen Automator it’s clear that it’s needed more than ever: if nothing else, there are holes in the way Automator works for those applications that support it, and there are plenty of applications that don’t. Some things, however, are worth the wait. Script Debugger 4.0, Late Night Software’s flagship AppleScript editor, is a ground-up rewrite of what was an already excellent product. Even if we do still need to edit AppleScripts, Apple already includes an AppleScript editor, so why bother with a third-party replacement? Well, Script Debugger 4.0 is much more than just an editor.
Script Debugger includes its own version of the AppleScript OSA component. That means you open a script window, set the language to AppleScript Debugger X, and just write your script as you normally would. However, because you’re using Script Debugger 4.0’s OSA component, it controls the way your AppleScript is executed. Via its deceptively simple interface you get the sort of debugging controls that one would expect in a professional programming environment – execute, step over, step into, step out – so you can see your code run, a command at a time.
Each Script Debugger 4.0 script window has its own drawer containing a results box, a stack list (so you can see which AppleScript routines are currently being called, a variable viewer (for showing the current state of variables in scope), an expression area (where you can construct useful debugging AppleScript expressions that are evaluated at every step), and an execution clock (which lets you know how long your script is taking). If a variable or expression changes between steps, then the new value is shown in red, making it easier to see the effects your code causes.
At any stage, you can select expressions within your code, place your cursor over the selection and wait: up pops a tool-tip telling you exactly what the selected expression evaluates to at that point. As you step through a script, the left-hand margin is highlighted to indicate code coverage, telling you exactly which lines of your script have been executed. This is extremely useful for ferreting out routines in old code that aren’t actually being used.
The debugging process has itself been improved upon. You can now debug more than one script at a time, so for the first time it’s possible to debug complex script interactions. More than that, you now have an option called ‘break-on-exception’, which traps any serious errors before they stop your script executing, letting you step back to where the error occurred so you can see what caused it. If you’re using the built-in AppleEvent logging, there’s now a contextual menu item that takes you from the log entry straight to the line of your script that caused it.
Debugging an existing script is one thing – writing one is quite another. AppleScript’s great strength is that each scriptable application extends the functions available to the scripter. It’s also a weakness, as figuring out the correct syntax for a command or object reference can be a nightmare. This is the area in which historically Script Debugger has really excelled, and thankfully Script Debugger 4.0 is no exception.
Using Script Debugger’s dictionary window it’s possible to view the commands, and AppleScript classes that each scriptable application understands. The way scriptable apps store their dictionaries has changed under OS X. Script Debugger 4.0 not only makes great use of this new ‘sdef’ format (which, depending on the application, may include expanded documentation and sample code), it can also construct ‘sdef’ data from more traditional ‘aete’ resources. The Dictionary can be viewed as both textual documentation, and an object hierarchy. Dictionaries can be searched, either via the Dictionary window, or from the script window’s contextual menu. Dictionary entries are attractively laid out as HTML documentation, and include hyperlinks so you can jump to the entries for related terms. (Where possible, it even highlights objects in the object hierarchy.)
For a more dynamic version of an application’s dictionary, you can switch to the Explorer mode. This lists the current objects, and their values, for the application in question – you can then drag and drop an item from the explorer to your script and have Script Debugger figure out how to reference the object. This, and the ability to see how objects relate, makes scripting much easier.
If you’re an old hand, don’t worry; the powerful ‘Tell Context’ palette is still there (which provides an Explorer-type view of the objects from the point of view of where the text cursor is in the current script window), as are the clippings and windows palettes. But no update is without some problems. The script palette is temporarily AWOL from this version, as is the script menu, and indeed Script Debugger 4.0’s very scriptability. Apparently this is down to a known Cocoa/AppleScript problem, so although a fix is in the works, it’s down to Apple.
As some compensation for this, the clippings feature has been enhanced to include three expansion tags, so that when you drag a clipping from the palette it can do something intelligent with the selection. Sadly, editor windows no longer support split-panes, so large editing larger scripts can be a bit frustrating. But again, an update that will include this feature is apparently in the pipeline.
Script Debugger 4.0 is almost everything an upgrade should be. Late Night Software seems to have taken every opportunity to condense and simplify Script Debugger’s interface, at the same time providing easier access to more powerful tools and better debugging information. If you script, buy it.