Re: NSAppleScript with threading
Re: NSAppleScript with threading
- Subject: Re: NSAppleScript with threading
- From: Daniel Jalkut <email@hidden>
- Date: Sun, 8 May 2005 18:45:07 -0700
On May 8, 2005, at 1:44 PM, email@hidden wrote:
So how can I execute AppleScript scripts using NSAppleScript keeping
my GUI responsive to user interactions ??
You're not going to like this, but it isn't possible. About the
only thing
I can think of would be to execute the 'osascript' task.
This isn't entirely true. Look at Script Editor. It's "playing by
the rules" with regard to threads and AppleScript, but it still
accomplishes what the original poster asked for: executing
AppleScript while remaining responsive to the user.
It's accomplished by intercepting the AppleEvent operations that
comprise a script's execution. During those interceptions, the app
then has the opportunity to "run the event loop" to maintain user
interaction.
Unfortunately, it seems like there isn't one single event callback
that you can install to keep attentive throughout a script's
execution. The "Active Proc" is called repeatedly, but only while
the AppleScript code itself is being processed. So if you've got a
script that is trying to compute pi or something, this is where you
would get a lot of calls.
The "send proc" is called whenever AppleScript needs to send an
event. This is where you can basically tweak "everything else" to
your liking. You can substitute an idle proc that will get called in
place of AppleScript's default idle proc, etc.
Unfortunately the idle proc gets called periodically but, in my
experience, not all the time. For instance when a script is waiting
on a dialog being displayed by the script, I don't think the idle
proc gets called.
Anyway, long story short: no, it's not impossible. Script Editor (and
probably Script Debugger and Smile?) prove this. It's definitely
trivially easy, and it does require managing all of the execution on
a single thread.
Daniel
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden