• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting a handler to use a value from a different handler?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
  • Follow-Ups:
    • Re: Getting a handler to use a value from a different handler?
      • From: Michelle Steiner <email@hidden>
References: 
 >Getting a handler to use a value from a different handler? (From: Brett Conlon/HU/Music-AU/SONY <email@hidden>)

  • Prev by Date: Re: Make New File in System Events
  • Next by Date: Re: Problem with dot_underscore files
  • Previous by thread: Re: Getting a handler to use a value from a different handler?
  • Next by thread: Re: Getting a handler to use a value from a different handler?
  • Index(es):
    • Date
    • Thread