Script Debugger lets you run individual handlers in a script. This can be a valuable testing and debugging technique.
You can run a standard event handler, such as an idle handler, an open handler, or a Folder Action handler. To do so, choose from the Event Handler menu:
Choose the handler from the hierarchical Script > Execute submenu.
Or, hold down the mouse down on the Execute button in the toolbar. A pop-up menu appears; choose the handler in this menu.
When you’re debugging a script, the same pop-up menu is attached to the Trace, Step Over, and Step Out menu items and toolbar buttons.
For example, consider the applet script in the illustration below. If you simply run this script, you’ll see the “Howdy!” dialog. That’s because what you’ve just run is the run handler. But what if you want to test the idle handler? Choose Idle from the Event Handler menu.

A
continuestatement in an event handler called in this way will generate an error in Script Debugger. This is deliberate and may be safely ignored. The technical reason is that if, for example, we permitted acontinue quitstatement in a script’squithandler to execute, Script Debugger itself would quit!
When you choose from the Event Handler menu, that event becomes the script’s current event. This means that the event is now called by default when you run the script.
To alert you to this special situation:
The current event is checked in the menu.
If the current event is not the run handler, a current event indicator appears below the toolbar of your script window:
To set the script’s current event back to the run handler:
Click the “x” in the current event indicator.
Or, choose Run from the Event Handler menu.
To set a different current event without also running that event handler:
The open handler and the event handlers defined in the Folder Actions and Digital Hub Actions suites expect parameters, which are aliases or files.
For example, an open handler expects a list of aliases to the files and folders. An adding folder items to handler expects two parameters, an alias to the watched folder and a list of aliases to the added files. And so forth.
Such a handler is listed in the Event Handler menu with an ellipsis (…) after its name. When you choose it from the Event Handler menu, Script Debugger presents a dialog where you can select files and folders. An appropriate parameter or parameters will then be passed to the specified handler.
In the case of
adding folder items toandremoving folder items from, what you’re supplying in this dialog is the second parameter, the item(s) that are allegedly being added or removed. Script Debugger will then use the containing folder of the item(s) as the first parameter, the watched folder.In the case of just the
openhandler, there is another alternative. Drag-and-drop files and folders directly from the Finder into your script. If your script has anopenhandler, one of the options in the resulting dialog is to invoke theopenhandler with these Finder items as parameter.
Script Debugger remembers each alias or list of aliases produced in this way, along with the event handler it is to be passed to, and adds this information to the bottom of the Event Handler menu. This list of remembered event handlers and parameters is the event history.
Thus, the next time you want to test this same handler with these same parameters, you can choose it from the event history (or, if it is the current event, click the Execute button).

The event history is remembered until you close the script window; or you can deliberately remove it by choosing Clear Menu (which is always the last item in the Event Handler menu if there is an event history).
If the handler you want to test is not one of the standard event handlers already listed in the Event Handler menu, you can test it using Script Debugger’s scriptability, which allows one script to call a handler in another script.
For example, suppose you have opened a script file named MyCoolScript.scpt containing this top-level handler:
    on justName(s)
        set text item delimiters to ":"
        return last text item of s
    end justName
    To test this handler without running the rest of MyCoolScript, run this script (from a different tab or script window):
    tell document "MyCoolScript.scpt"
        justName("hey:ho:nonny nonny no")
    end tell
    This calls justName in the complex script. Moreover, it adds this handler call with this parameter to the event history. Thus, having done this once, you no longer need the second script in order to test the first.
