Coercing a string to a handler name?

I’m trying to do somthing like this:

set x to "foobar"
my handler x() -- this fails

on foobar()
log("foobar invoked")
end foobar

I’ve tried this a number of ways, but none of them work. How can this be done?

I think it’s possible, because I found a similar question answered in the Apple Mailing List archives. Unfortunately, the answer was truncated and only the first few lines of it remain, and that isn’t enough information for me to piece together the solution.

Thanks in advance.


you can do it this way

on foobar(t)
	say t
end foobar

set x to foobar

Thank you. But what if the name of the handler is passed to the script via a string?

For example:

set x to text returned of (display dialog "Handler name?" default answer "")

	my handler x() -- this always fails, even if x is set to "foobar"
on error
	log("invalid handler name: " & x)
end try

on foobar()
end foobar