Does anyone know how you can run a handler in the calling script, from the library. For example, I tried this:
use framework "Foundation"
global theSender
on doIdle:t sender:sender
set theSender to sender
theSender
performSelector_withObject_afterDelay_(theSender's "idleScript", t,2)
end doIdle:sender:
It won’t compile with: theSender’s “idleScript”. Here’s the calling script:
use theScript : script "SysLib"
use scripting additions
theScript's doIdle:5 sender:me
on idleScript(t)
display dialog t
return
end idleScript
One of the sample scripts with ASObjC Explorer is this:
use framework "Foundation"
(* This must be run from the main thread *)
-- The exported lib will obviously only work with stay-open applets.
on callLater:sender
my performSelector:"doItNow:" withObject:sender afterDelay:2 -- will show dialog after 2 seconds
end callLater:
on doItNow:sender
sender's showDialog:"Hello World"
end doItNow:
Called like this:
use theLib : script "^" -- required
use scripting additions
-- Requires the main thread.
-- call lib handler
tell theLib to callLater:me
-- called by lib after delay
on showDialog:value
log value
display dialog value
end showDialog:
Thanks Shane. Giving up routines from your book. But then, you,ve posted many helpful snippets. It just so happened that a lot of the nephews and nieces decided to visit, so I’ll look into your script. On the outside it looks great. I’m still wondering how you ran a handler in the calling script.
I’m not sure how to answer – the calling script gets passed as sender, which then gets passed to doItNow:, and is then used as the target for the call to showDialog:.