【问题标题】:Can I get the actual Menu Bar from an NSRunningApplication?我可以从 NSRunningApplication 获取实际的菜单栏吗?
【发布时间】:2012-12-13 08:52:53
【问题描述】:

我正在尝试访问 OS X 中 NSRunningApplication 对象的菜单。它有一个 ownsMenuBar @property,但是没有实际菜单栏的实例(这是有道理的)。相反,我很好奇如何访问NSRunningApplication 知道何时存在的菜单栏。也许是KVO? NSRunningApplicationNSApplication 之间是否存在任何(甚至很小的)关系?

谢谢!

-----编辑-----

djai djan,你非常乐于助人,这是我根据你的建议设法完成的代码!

tell application "System Events"
    return menu bar of first process where frontmost is true
end tell

【问题讨论】:

  • 标题与正文无关
  • 已更改。对不起):

标签: objective-c macos key-value-observing nsapplication nsrunningapplication


【解决方案1】:

NSRunningApplicationNSApplication 之间没有关系

但是您可以通过 applescript 获得它(您可以桥接到可可)需要 UI 脚本

脚本例如:

tell application "System Events"
    set m to menu bar 1 of application process "Notification Center"
end tell

见:https://developer.apple.com/documentation/Cocoa/Conceptual/ScriptingBridgeConcepts/index.html

【讨论】:

  • 如果结果不正确,请告诉我。如果是这样,我会做更多的挖掘
猜你喜欢
  • 1970-01-01
  • 2015-09-09
  • 2018-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多