Language Guide

CHAPTER 9
Script Objects
Using the Copy and Set Commands With Script Objects 283
Because the script object Bilbo declares the Scriptable Text Editor as its parent
property, the on display dialog handler must use a Tell statement to send
a separate Display Dialog command to the Script Editor. The handler then uses
a Continue statement to pass the original Display Dialog command to the
Scriptable Text Editor, which becomes the frontmost application and uses the
Display Dialog addition to display “Hello”.
Using the Copy and Set Commands With Script Objects 9
The Copy and Set commands both assign values to variables, but they have
different results when the value assigned is a script object. The Copy command
makes a new copy of the script object, and the Set command creates a variable
that shares data with the original script object.
To see how this works, consider the following example, which defines a script
object, called John, with a property called Vegetable.
script John
property Vegetable: "Spinach"
end script
set myScriptObject to John
set Vegetable of John to "Swiss chard"
get Vegetable of myScriptObject
--result: "Swiss chard"
The first Set command defines a variable, called myScriptObject, that shares
data with the original script object John. The second Set command changes the
value of the Vegetable property of script object John from "Spinach" to
"Swiss chard". Because myScriptObject shares data with John, it shares
the change to the Vegetable property of John. When you get the Vegetable
property of myScriptObject, the result is "Swiss chard".