Can you use KVO with Scripting Bridge
Can you use KVO with Scripting Bridge?
I want to know if I can make an Scripting Bridge interface for my application and allow client applications to be notified by observing an object returned by one of my app's SB commands.
Is this possi开发者_运维技巧ble? If not, what's an alternative?
Scripting Bridge objects are just Cocoa-flavored sugar around sending events to the application and getting replies back. If you observe a property of an object, you aren't sending it any messages, so you wouldn't be sending the application any events. There is no way in the Apple Events system to observe something—you can send events and get replies, and that's it.
The only way to do what you want is to poll: Send the application an event every x seconds asking for the current state.
If you're trying to observe the current track or playing status in iTunes, then for that and that alone, you don't need to poll, because iTunes posts an (undocumented) distributed notification when the current track or playing status changes. You can use Notification Watcher to examine the notification when it comes in so you know what to extract from it.
I have found an alternative solution called Distributed Objects for anyone who cares about my question.
精彩评论