Abstract:
Sending AppleEvent or executing AppleScripts on any thread in a parallel (asynchronous) manner from a Cocoa App.
Dear List, I'm posting this here as i think it's the most appropriate one. If not, please tell me.
Symptom 1 Crash:
Reading the documentation, i'm told that executing AppleScripts on any thread is supported since 10.6. After shipping my app in early versions we had crashes sent back to us reading that something in this area is not working as described. We were doing it with something in the line of TCallScript using executeAppleEvent.
Symptom 2 Hang (spin):
After these reports, we changed the code so the app only sends from main-thread. After shipping this version, he had hang-reports reading that AppleScript is blocking the main thread. We do it now with NSAppleScript executeAndReturnError
Both symptoms are not reproducible. No pattern in targeted Apps, no pattern in OS-Version, CPUs with 2 or 8 cores seem less affected than ones with 4.
One idea: the first symptom is caused by GCD/NSOperationQueue threads that don't have a running runloop. Second symptom is caused by sending new AE before first return.
I'd like having it as robust as possible.
Questions:
* Does anyone has experienced the same thing? I found discussions on this subject but all pre Snow Leopard.
* Is having a dedicated NSThread for all AE-Communications the recommended way of doing it?
* Would you recommend having another thread monitoring the AE-Thread and stopping it when spinning for too long? (watchdog polling every second?)
* Are there limitations to sending AE from different threads parallel (not waiting for the first to answer)?
* What's the mystery behind AESendMessage and an answer port? Is it a recommended way to go?
* Should we even consider SBApplication (Scripting Bridge) to make it more robust?