是否可以监视 OS X 上其他应用程序的事件?
本质上,我需要知道何时有人在 iTunes 中点击播放。我了解如何使用 Apple 的脚本桥控制 iTunes,但我似乎无法让 iTunes 控制我的应用程序。这可能吗?
谢谢!
Essentially, I need to know when someone hits play within iTunes. I understand how I can control iTunes using Apple's Scripting Bridge, but I can't seem to make iTunes control my app. Is this possible?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,不可能弄清楚其他应用程序对事件做了什么,不是。您也不可能知道 iTunes 中的播放按钮何时被按下。即使您要捕获鼠标按下事件,您也必须以某种方式确定 iTunes 的播放按钮当时是否位于该事件下方。
然而,在这种情况下,您可以做的是注册 iTunes 在曲目开始播放时发布的通知。 Dave DeLong 在 另一个答案 这里就这样。
这并不能满足你所希望的一切; 分布式通知很昂贵,因此 iTunes 对它们很节俭。当曲目开始播放时,您会收到通知,仅此而已;没有停止,没有音量,跳轨和从停止开始播放之间没有区别。不过,该通知确实包含有关曲目本身的大量信息:几乎所有 iTunes 元数据以及一些文件信息。
希望这有用!
In general, it's not possible to figure out what other apps are doing with events, no. It is also not possible for you to find out when the play button in iTunes is pressed. Even if you were to catch the mouse down event, you'd have to somehow figure out whether iTunes's play button was under it at the time.
What you can do in this case, however, is register for the notifications that iTunes posts when a track starts playing. Dave DeLong has laid it out, in another answer here on SO.
This doesn't give you everything you might hope for; Distributed Notifications are expensive, and so iTunes is frugal with them. You get a notification when a track starts playing, and that's it; no stop, no volume, no distinction between jumping tracks and starting playing from a stop. The notification does have plenty of info about the track itself, though: pretty much all the iTunes metadata, and some of the file info.
Hope that's useful!