Scope of Subroutine Calls in Tell Statements
If you need to call a subroutine from within a Tell statement, you must use the reserved wordsof meormyto 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
minimumValuesubroutine call in the following Tell statement is unsuccessful, because AppleScript sends theminimumValuecommand to the Scriptable Text Editor. (You get an error message saying
that the Scriptable Text Editor does not understand theminimumValuecommand.)
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 wordsofmein 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 wordmybefore the subroutine call is a synonym for the wordsof meafter the subroutine call. For example, the following two subroutine calls are equivalent:
minimumValue(12, 400) of me my minimumValue(12, 400)