Language Guide
CHAPTER 8
Handlers
224 Using Subroutines
Scope of Subroutine Calls in Tell Statements 8
If you need to call a subroutine from within a Tell statement, you must use the
reserved words of me or my to indicate that the subroutine is part of the
script—not a command that should be sent to the object of the Tell statement.
For example, the minimumValue subroutine call in the following Tell
statement is unsuccessful, because AppleScript sends the minimumValue
command to the Scriptable Text Editor. (You get an error message saying
that the Scriptable Text Editor does not understand the minimumValue
command.)
tell application "Scriptable Text Editor"
minimumValue(12, 400)
copy result as string to word 15 of front document
end tell
(* result: the subroutine call is unsuccessful because
AppleScript sends the minimumValue command to the
Scriptable Text Editor *)
If you use the words of me in the subroutine call, as shown in the following
Tell statement, the subroutine call is successful, because AppleScript knows
that the subroutine is part of the script.
tell application "Scriptable Text Editor"
minimumValue(12, 400) of me
copy result as string to word 15 of front document
end tell
(* result: the subroutine call is successful because the
words "of me" tell AppleScript that the minimumValue
command is part of the script *)
The word my before the subroutine call is a synonym for the words of me after
the subroutine call. For example, the following two subroutine calls are
equivalent:
minimumValue(12, 400) of me
my minimumValue(12, 400)