• 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
In a handler passed as a parameter to a handler in another script, how do I refer to top-level variables from the original script?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

In a handler passed as a parameter to a handler in another script, how do I refer to top-level variables from the original script?


  • Subject: In a handler passed as a parameter to a handler in another script, how do I refer to top-level variables from the original script?
  • From: DeNigris Sean <email@hidden>
  • Date: Tue, 28 Jul 2009 02:04:08 -0400

Example:
From my main script file:
-- A utility library
set expose_lib to load script alias "path:to:Scripts:My Library:Expose.scpt"
        set UI_lib to load script alias "path:to:Scripts:My Library:UI.scpt"

-- Handlers in  that will be used as parameters:
to return_to_space()
expose_lib's set_current_space(theCurrentSpace)
end return_to_space

on did_space_return()
return (expose_lib's current_space() is theCurrentSpace)
end did_space_return

-- Pass the handlers to another script
        UI_lib's rerun({this_script:return_to_space, until_predicate:did_space_return})

The UI_lib file, containing a generic handler that takes handlers as parameters:
--rerun({this_script:code_to_run, until_predicate:my_predicate, or_seconds_elapsed:5})
to rerun(record_of_parameters)
set defaults to {or_seconds_elapsed:2}
set record_of_parameters to record_of_parameters & defaults

script usable_command
property theHandler : record_of_parameters's this_script
theHandler()
end script

script usable_predicate
property theHandler : record_of_parameters's until_predicate
theHandler()
end script

set start_time to (get time of (current date))
repeat while not (run usable_predicate)
run usable_command
if (get time of (current date)) - start_time > record_of_parameters's or_seconds_elapsed then
exit repeat
end if
end repeat
end rerun

When I run the script, I get "The variable expose_lib is not defined." because the script that's running is the UI_lib script.  Is there any way I can do this without changing the rerun handler, which is a generic library handler?

Sean DeNigris
email@hidden



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: In a handler passed as a parameter to a handler in another script, how do I refer to top-level variables from the original script?
      • From: Tetsuro KURITA <email@hidden>
    • Re: In a handler passed as a parameter to a handler in another script, how do I refer to top-level variables from the original script?
      • From: Axel Luttgens <email@hidden>
  • Prev by Date: Re: Unwanted dialog if mounting fails
  • Next by Date: Re: Unwanted dialog if mounting fails
  • Previous by thread: Indexing Quark
  • Next by thread: Re: In a handler passed as a parameter to a handler in another script, how do I refer to top-level variables from the original script?
  • Index(es):
    • Date
    • Thread