technical -handlers-


usually, I write:

set var to my call_handler()

on call_handler()

instead of:

set var to call_handler()

to call_handler()

whats the difference, efficiency in between those two approaches ?
my’ should be faster before ‘to’, in the first place.
But i do not understand the handler formulation:

to call_handler()


to and on are synonyms, they do technically exactly the same.

The keyword my is an explicit reference to the current script (object),
it’s needed to call a handler within any application tell block, because a handler belongs to AppleScript itself.
For a more detailed description please look here

Hello! :slight_smile:

I wrote this handler, and remembered this post, and thought it was appropriate!

When you use to you get access to prepositional parameters by which, you can almost form your own language. :smiley:
It is properly explained in the ASG, that Stefan posted a reference to above.

       openFinderWindow of me for "Hd Macintosh:Users:Me:Desktop:"

to openFinderWindow for folderName
	” reuses the window if already opened
        ” Doesn't consider which space	
	tell application "Finder"
		set aw to (get its every Finder window) as list
		set hw to {}
			set aliasOfit to folderName as alias
		on error
				set aliasOfit to (POSIX file folderName as text) as alias
			on error
				error folderName & "is not a valid folder specifier"
			end try
		end try
		repeat with w in aw
			if (target of w as alias) is aliasOfit then
				copy w to end of hw
				exit repeat
			end if
		end repeat
		if not hw is {} then
			select item 1 of hw
			open aliasOfit
		end if
	end tell
end openFinderWindow

As mentioned above, on and to are synonyms for a handler definition, this works as well even without using of me

openFinderWindow for (path to desktop as text)

on openFinderWindow for hfsPath


I wasn’t quite aware of that, I thought actually that on was reserved for positional parameters. :slight_smile: