Handler in a tell block - scope?

In a tell block which references a specific application I want to use some handlers to manipulate the application’s objects and also external objects which might be needed, such as AppleScript’s text delimiters. Will the handler commands recognize application objects without a tell statement referencing the application explicitly? What’s the right way to do this?

Thanks for any insights.


Each handler must contain ‘tell’ statements for any application used in it. A call to a handler from within a ‘tell’ block must be preceded by ‘my’ to identify the handler as something belonging to the script and not to the application. You don’t need to make any special provisions for passing application objects as parameters.

tell application "My App"
	-- Blah blah.

	my subroutine(param)
	-- Blah blah
end tell

on subroutine(param)
	tell application "My App"
		-- etc.
	end tell
end subroutine
tell application "Finder"
	set y to disk "Macintosh HD"
end tell


on bof(x)
	properties of x
end bof

In this case disk “Macintosh HD” is a reference to an object of application Finder, and it works as such in the handler.

As long as you are sure you have a reference to object y of application z, it works. Walk carefully in this slippery slope.

If you need a property of x or a verb whose name is only known to the Finder, of course this doesn’t work, failing at compile time.

Nice to be concious about. That may come in handy one day! :slight_smile:

Thanks for reply. Clears things up for me. I had not understood too well the use of “my.” In scripting an AS application with a handler definition one could actually have something like this, where calculateF is defined (possibly differently) in both the AS application and the script (?):
tell application “theASapp”

my calculateF(calculateF(X,Y),Z)
or alternatively
set Y to calculateF(X,Y)
my calculateF(Y,Z)

end tell

on calculate(Y,Z)
–do something
end calculate
-----------end script---------

Thanks. Now I know why I got so many inexplicable errors, particularly those “unable to coerce” errors that have occurred apparently in defiance of common sense but not logic. :stuck_out_tongue:

For peace of mind reasons you should use the alternative form. Your code might be read by a psycopath that knows where you live. :lol:

Not a problem. I’ll have the fava beens already heated and a bottle of fine chianti cracked and breathing. :lol:

ps- The above should NOT be interpreted as a maniacal LOL.