Language Guide
CHAPTER 9
Script Objects
282 Inheritance and Delegation
You can make any application the current application for a script or script
object simply by declaring it as a parent property. Any subsequent command in
the script for which the script doesn’t have a handler is passed to the
application you declare as the parent, and subsequent occurrences of the
constant current application refer to that application.
For example, this script declares the Scriptable Text Editor as its parent
property, then sends commands that close the Scriptable Text Editor’s
frontmost window and return the application’s name:
property parent: application "Scriptable Text Editor"
close front window
tell current application to return my name
In this case, my refers to the current application (Scriptable Text Editor). The
Tell statement is optional; just return the name of me would produce the
same result, because AppleScript sends the command to the Scriptable Text
Editor. If you remove the property declaration from the script, the Script Editor
becomes the current application. When sent to the Script Editor, the Close
command and the Return statement produce errors because the Script Editor
doesn’t understand them.
In the next example, the script Bilbo declares the Scriptable Text Editor as
its parent property and includes a handler that modifies the behavior of
the scripting addition command Display Dialog.
script Bilbo
property parent : application "Scriptable Text Editor"
on display dialog x
tell application "Script Editor" to display dialog ¬
"Scriptable Text Editor has something to say"
continue display dialog x
end display dialog
end script
tell Bilbo to display dialog "Hello"