GCD and AppleEvents / NSOperationQueue and AppleScript
As I understand it, the streams provided by GCD have a runloop, but no source / port. Now I am using some methods that call AppleScripts via AppleEvents inside NSOperationQueue. And sometimes my application crashes with the following stacktrace command.
my questions:
- Using AppleScript inside NSInvocationOperation or NSBlockOperation
- Using AppleEvents inside GCD-Threads
- Do I need to add source / port to runloop gcd-thread before using AppleEvents?
- Do I need to add source / port to runloop gcd-thread before using [CATransaction commit]?
- Do I need to add source / port to runloop gcd-thread before using [NSObject performSelectorAfterDelay ...]?
- if so, how?
- Is it possible to just call CFRunLoopRunInMode (kCFRunLoopDefaultMode, 5.0, false); /// or 30 or a specific appleevent timeout?
.. Thread 9: Dispatch queue: com.apple.root.default-priority 0 libSystem.B.dylib 0x00007fff88276e82 semaphore_wait_signal_trap 10 1 libSystem.B.dylib 0x00007fff8827c3cd pthread_mutex_lock 469 2 com.apple.applescript 0x000000011d3d461f AppleScriptComponent 50 3 com.apple.applescript 0x000000011d3edbcc AGenericCall :: Delegate (ComponentInstanceRecord *) 46 4 com.apple.applescript 0x000000011d3ed520 AGenericManager :: HandleOSACall (ComponentParameters *) 54 5 com.apple.applescript 0x000000011d3ed4b0 GenericComponent 219 6 com.apple.openscripting 0x00007fff8381c6da OSAExecuteEvent 63 7 com.apple.Foundation 0x00007fff86f320d8 - [NSAppleScript (NSPrivate) _executeAppleEvent: withMode: error:] 161 8 xxx 0x0000000100048af0 - [TCallScript callScript: withArrayOfParameters:] 480 9 xxx 0x0000000100048ffd - [TCallScript callHandler: withParameters:] 477 10 xxx 0x0000000100036032 - [ZFOpenWindowController getSafariItemForCurrentTabForWindow:] 66 11 xxx 0x00000001000346af - [ZFOpenWindowController refreshWindowList:] 1679 12 xxx 0x000000010003541c - [ZFOpenWindowController bringZFToForegroundZoomOut: orJustLinkFrontMost: toItem:] 2988 13 xxx 0x0000000100053556 __- [ZFSelectionTool openWithPreferredApplication:] _ block_invoke_516 54 14 com.apple.Foundation 0x00007fff86ed87d9 - [NSBlockOperation main] 140 15 com.apple.Foundation 0x00007fff86ec906d - [__ NSOperationInternal start] 681 16 com.apple.Foundation 0x00007fff86ec8d23 ____startOperations_block_invoke_2 99 17 libSystem.B.dylib 0x00007fff882b2ce8 _dispatch_call_block_and_release 15 18 libSystem.B.dylib 0x00007fff88291279 _dispatch_worker_thread2 231 19 libSystem.B.dylib 0x00007fff88290bb8 _pthread_wqthread 353 20 libSystem.B.dylib 0x00007fff88290a55 start_wqthread 13 ... Thread 11 Crashed: Dispatch queue: com.apple.root.default-priority 0 com.apple.applescript 0x000000011d40f658 BCHandleError () 182 1 com.apple.applescript 0x000000011d4059ca UASExecute1 () 2546 2 com.apple.applescript 0x000000011d3dd1d5 ASExecuteEvent (AEDesc const *, unsigned int, int, unsigned int *) 695 3 ... ple.CoreServices.CarbonCore 0x00007fff85388e04 CallComponentFunction 28 4 com.apple.applescript 0x000000011d3d4cad AppleScriptComponent 1728 5 com.apple.applescript 0x000000011d3edbcc AGenericCall :: Delegate (ComponentInstanceRecord *) 46 6 com.apple.applescript 0x000000011d3ed520 AGenericManager :: HandleOSACall (ComponentParameters *) 54 7 com.apple.applescript 0x000000011d3ed4b0 GenericComponent 219 8 com.apple.openscripting 0x00007fff8381c6da OSAExecuteEvent 63 9 com.apple.Foundation 0x00007fff86f320d8 - [NSAppleScript (NSPrivate) _executeAppleEvent: withMode: error:] 161 10 xxx 0x0000000100048af0 - [TCallScript callScript: withArrayOfParameters:] 480 11 xxx 0x0000000100048ffd - [TCallScript callHandler: withParameters:] 477 12 xxx 0x0000000100035c67 - [ZFOpenWindowController getItemForAXDocumentOfFrontMostWindow] 119 13 xxx 0x00000001000359f1 - [ZFOpenWindowController getItemForFrontMostWindow:] 721 14 xxx 0x00000001000348ac - [ZFOpenWindowController bringZFToForegroundZoomOut: orJustLinkFrontMost: toItem:] 60 15 xxx 0x0000000100053556 __- [ZFSelectionTool openWithPreferredApplication:] _ block_invoke_516 54 16 com.apple.Foundation 0x00007fff86ed87d9 - [NSBlockOperation main] 140 17 com.apple.Foundation 0x00007fff86ec906d - [__ NSOperationInternal start] 681 18 com.apple.Foundation 0x00007fff86ec8d23 ____startOperations_block_invoke_2 99 19 libSystem.B.dylib 0x00007fff882b2ce8 _dispatch_call_block_and_release 15 20 libSystem.B.dylib 0x00007fff88291279 _dispatch_worker_thread2 231 21 libSystem.B.dylib 0x00007fff88290bb8 _pthread_wqthread 353 22 libSystem.B.dylib 0x00007fff88290a55 start_wqthread 13
+2
a source to share
1 answer
Note that the AppleScript component has limited thread safety. Since 10.6, you can use it for non-main threads, but you will need to create a new ComponentInstance for each thread. I think you can do it with OSAKit, otherwise you have to resort to the gnarly Carbon API. What is best depends on what you are trying to achieve (for example, you are using user-supplied scripts or scripts hard-coded into your application and what prompts them to run through NSOperationQueue).
0
a source to share