您可以将 KVO 与 Scripting Bridge 一起使用吗

发布于 2024-09-25 11:46:25 字数 140 浏览 1 评论 0原文

您可以将 KVO 与 Scripting Bridge 一起使用吗?

我想知道是否可以为我的应用程序创建一个脚本桥接口,并允许通过观察我的应用程序的 SB 命令之一返回的对象来通知客户端应用程序。

这可能吗?如果没有,有什么替代方案?

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 possible? If not, what's an alternative?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

多情出卖 2024-10-02 11:46:25

脚本 Bridge 对象只是将事件发送到应用程序并获取回复的可可味糖。如果您观察对象的属性,则不会向其发送任何消息,因此您不会向应用程序发送任何事件。 Apple Events 系统中无法观察某些内容 - 您可以发送事件并获取回复,仅此而已。

执行您想要的操作的唯一方法是轮询:每 x 秒向应用程序发送一个事件,询问当前状态。

如果您尝试观察 iTunes 中的当前曲目或播放状态,那么仅此而已,您就不需要进行轮询,因为当当前曲目或播放状态发生更改时,iTunes 会发布(未记录的)分布式通知。您可以使用 Notification Watcher 来检查通知,以便您知道从中提取什么内容。

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.

甜是你 2024-10-02 11:46:25

我找到了一个名为 分布式对象 的替代解决方案对于任何关心我的问题的人。

I have found an alternative solution called Distributed Objects for anyone who cares about my question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文