Re: Getting a handler to use a value from a different handler?
Re: Getting a handler to use a value from a different handler?
- Subject: Re: Getting a handler to use a value from a different handler?
- From: Christopher Nebel <email@hidden>
- Date: Tue, 18 Oct 2005 08:20:01 -0700
On Oct 17, 2005, at 10:15 PM, Brett Conlon/HU/Music-AU/SONY wrote:
...Now that the prompt is separated from the "replace" handler I
can't figure how to get the variable replacement_string defined in
the first handler to be associated with the replacement_string of
the replacement handler.
There are two basic ways to deal with this sort of thing. One is to
give "replacement_string" a bigger scope than local-to-the-handler,
such as by using a top-level variable or a property such as M.
Saunders suggested. The other (cleaner and more maintainable!) way
is to use handler return values and parameters. For example:
on AskTitle()
set d to display dialog "Title:" default answer ""
set answer to text returned of the result
return answer
end
on ReplaceText(replacement_text)
(* magic goes here *)
end
on run
set replacement_string to AskTitle()
ReplaceText(replacement_string)
end
The upshot is that the "answer" returned from AskTitle becomes the
value of "replacement_text" in ReplaceText. This sort of thing is
covered in the "Handlers" chapter of the AppleScript Language Guide
<http://developer.apple.com/documentation/AppleScript/Conceptual/
AppleScriptLangGuide/>. If you haven't read any documentation on
AppleScript yet, you should -- it will save you a lot of trouble in
the long run. The ASLG is more a reference than an instructional
manual, but there are several third-party books that are more "teach-y".
--Chris Nebel
AppleScript and Automator Engineering
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden