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?
|