Running an AppleScript from a background thread

Hi all,

I’m trying to find a way to get an AppleScript to run without it blocking the main thread of my application. (The application happens to be made with REALbasic, but that shouldn’t really be important, I hope).

Here’s my current problem. If I run my AppleScript (which asks iTunes for some info about a track based on the track id), the script can sometimes take a few seconds to run. Whilst it is running, it blocks the application’s main thread (as would be expected), which causes audio dropouts in QuickTime movies I am playing.

I do all other file loading and access on a background thread in my app, to avoid disturbing QuickTime’s audio playback. But I don’t know how to do this for AppleScripts.

So, what I think I need is to find some way to:

  • Run an AppleScript from a background thread from my application (is this possible?)
  • Obtain the information from iTunes, from a background thread, via some other means (would AppleEvents be useful here?)

Any ideas much appreciated!

Dave.

Browser: Safari 416.12
Operating System: Mac OS X (10.4)

Possible but difficult, due to the way the Apple Event Manager works. Reply events normally arrive on the main thread, and to get around this you need to muck about with AESendMessage() and mach ports. From http://developer.apple.com/technotes/tn2002/tn2053.html#TN001208:

Any chance you could just chuck the job off to a separate process? I reckon that’ll be a lot simpler. Otherwise, the AppleScript Implementors list would be a much more appropriate place to ask.

HTH