Your code never runs the runloop.
It adds and removes the ODQuery, but the runloop itself is never run.
In a Foundation Tool, no thread automatically runs its runloop, not even the main thread. That only happens in an application, and frankly, only because NSApplication does it (in short, it's not automatic, just built into NSApplication).
At a minimum, you need to add:
Code:
[[NSRunLoop currentRunLoop] run];
It should happen after:
Code:
[myQuery scheduleInRunLoop: [NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
And get rid of the second thread entirely. You don't need it, and coordinating that thread, its runloop, and the main thread is 10X more complex than it needs to be. A basic runloop should work fine here.
And you should review the fundamentals of runloops, especially in the context of a Foundation Tool. If you're writing a tool that uses any of the async functionality of Cocoa, which is a considerable portion of its utility, then you will need to be extremely familiar with runloops.
Apple's low-level info on runloops is best described in its Threading Guide. This doesn't mean you need to create threads. You just need to treat the main thread the same way the Threading Guide describes for secondary threads.
http://developer.apple.com/iphone/l...ding/RunLoopManagement/RunLoopManagement.html
You should also read the NSRunLoop class reference, in particular the run method and its discussion of alternatives.
I can't point you to Apple example code, but there are plenty of searchable resources:
http://www.cocoabuilder.com/archive/search/1?q=runloop+foundation+tool&l=cocoa
http://www.cocoadev.com/index.pl?RunLoop
Google keywords: site:
www.cocoadev.com run loop foundation tool
(The above may contain technical inaccuracies due to brevity, haste, and/or my own ignorance or indifference. Take them as general <handwave> outlines, not rigorous technical specifications.)