[英]Macos x Shortcuts of a Application
I need to read all Shortcuts of the frontmost Application in MAC OS. 我需要读取MAC OS中最前面的应用程序的所有快捷方式。 Is there a API or Class in Cocoa,Objective-c who provides this?
Cocoa中是否有API或类,Objective-c提供了这个?
The Accessibility API is what you need. Accessibility API就是您所需要的。 Unfortunately, it is rather convoluted, and it would be good to read through the UIElementInspector source code to see how it's used, as well as the sections relevant to assistive applications in the Accessibility Programming Guidelines for Mac .
不幸的是,它相当复杂,最好通过UIElementInspector 源代码来阅读它的使用方法,以及与Mac可访问性编程指南中的辅助应用程序相关的部分。
What you want would take a good bit of code so I will just outline the steps. 你想要的是需要一些代码,所以我将概述步骤。
[[NSWorkspace sharedWorkspace] runningApplications]
to get a list of applications and get the application whose active
property is YES
. [[NSWorkspace sharedWorkspace] runningApplications]
获取应用程序列表并获取其active
属性为YES
的应用程序。 NSRunningApplication
's processIdentifier
property. NSRunningApplication
的processIdentifier
属性获取该应用程序的PID。 AXUIElementCreateApplication
, which takes pid
as the argument. AXUIElementCreateApplication
创建表示活动应用程序的AXUIElementCreateApplication
,它以pid
作为参数。 AXUIElement
with the Application
role, or AXApplication
pseudo-class. Application
角色的AXUIElement
或AXApplication
伪类。 You'll want to proceed down the hierarch of elements AXApplication
-> AXMenuBar
-> AXMenuBarItem
-> AXMenuItem
. AXApplication
- > AXMenuBar
- > AXMenuBarItem
- > AXMenuItem
。 Note that AXMenuItems
can have other AXMenuItems
nested under them. AXMenuItems
可以嵌套其他AXMenuItems
。 AXUIElementCopyAttributeValues
to get the values of kAXChildrenAttribute
. AXUIElementCopyAttributeValues
得到的值kAXChildrenAttribute
。 This will return an array of children AXUIElements
. AXUIElements
。 AXMenuItem
elements, examine their Menu Item Cmd Char, Glyph, Modifiers, and Virtual Key attributes for the actual shortcuts. AXMenuItem
元素时,请检查实际快捷方式的菜单项Cmd Char,Glyph,Modifiers和Virtual Key属性。 The constants for the attribute names, like kAXMenuItemCmdCharAttribute
, are listed here . kAXMenuItemCmdCharAttribute
。 Not trying to compete @woody :) 不试图竞争@woody :)
But I found this, and it might help too: 但我发现了这一点,也可能有所帮助:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.