Script Library runs handler in calling script

Hi,

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

Think I might need to do something with NSTimer.

Thanks,
kel

Think I’ll try this next from the NSTimer:

I’m wondering if I can send the method back to the library script. Need to test that out.

Thanks,
kel

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.

Thanks a lot,
kel

Hi Shane,

I haven’t run it yet but it looks good.

Edited: I’m still wondering how you get it to run the handler in the calling script. Think I’ve tried that.

Thanks a lot,
kel

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:.

Hi Shane,

It works great. I was a bit confused with ’ tell theLib to callLater:me’, but that works also.

Thanks a lot,
kel