Using Continue Statements to Pass Commands to Applications
Scripting addition commands and application commands sent to script
objects don't trigger their associated actions until they're received by the default target application. This means you can use a handler for such commands within a script object to modify the way the command works
when sent to that script object.For example, the handler for the Beep command in the example that follows modifies the command by displaying a dialog box and allowing the user to decide whether to continue or not:
script Joe on beep set x to display dialog � "Do you really want to hear this awful noise?" � buttons {"Yes", "No"} if the button returned of x is "Yes" then � continue beep end beep end script tell Joe to beepWhen AppleScript encounters the Tell statement, it sends a Beep command to scriptJoe
. The Beep handler causes the default target application (for example, the Script Editor) to display a dialog box that gives the user a choice about hearing the alert sound. If the user clicks Yes, the handler uses a Continue statement to pass the Beep command to the default target application. If the user clicks No, the target application never receives the Beep command and no alert sound is heard.In applications that allow you to attach script objects to application objects, you can use a handler for an application command in a script object to modify the way the application responds to the command.
For example, if a drawing application allows you to associate script objects with geometric shapes such as circles or squares, you could include a handler like this in a script object associated with a shape in a document:
on move to {x, y} continue move to {x, item 2 of my position} end moveWhenever the shape the script object is associated with is named as the target
of a Move command, theon move
handler handles the command by modifying one of the parameters and using the continue statement to pass the command on to the default parent--that is, the drawing application. The location specified by {x, item 2 of my position} has the same horizontal coordinate as the location specified by the original Move command, but specifies the shape's original vertical coordinate (item 2 of the circle's original position), thus constraining the shape's motion to a horizontal direction.The documentation for applications that allow you to associate script objects with application objects in this manner should provide more information about how to write handlers for application commands.