[Adium-devl] Blocking AppleScript Commands

Evan Schoenberg evan.s at dreskin.net
Mon Apr 21 22:48:05 UTC 2008


On Apr 21, 2008, at 6:30 PM, Matt Handley wrote:

> Would it be possible to try to wait (runMode:beforeDate:) until the
> command timeout (which may be accessible from within Cocoa...)
> elapses? Were that possible, then without a timeout specified, then
> Adium would not block. Yet if the scripter wanted to be able to
> specify the elapsed time, he would still have such a mechanism.
>
> The only things I see as preventing this from working is if: a) there
> is no way to get the timeout field of the apple event (unlikely), b)
> if the right NSRunLoop is hard to get to (we're multi-threaded,
> right?), or c) if the NSRunLoop does tricky things that we don't
> necessarily want to run over and over again while we're waiting for a
> response from a server.

One could certainly iterate on the run loop until a response is  
received,  checking for the desired result after each iteration.   
Applescript can only run on the main thread; that run loop is easy to  
get.

However, this opens a can of worms. What happens when iterating on the  
run loop triggers another Applescript to run, or the same Applescript  
to run?  Hint: Applescript is not threadsafe and not re-entry safe.  
*boom*.  Yes, it'll work sometimes... and crash one time in several  
hundred cases of re-entry.

-Evan




More information about the devel mailing list