从另一个应用程序获取所有快捷键列表 [英] Get a list of all shortcuts from another application

查看:375
本文介绍了从另一个应用程序获取所有快捷键列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道是否有获得在其他应用程序的菜单栏的所有键盘快捷键present清单(如有可能,还从封闭的应用程序)的简单方法。

I'm wondering if there's a straightforward way of getting a list of all keyboard shortcuts present in the menubar of an other application (if possible also from closed applications).

我想在我写来简化配置我的Wacom平板电脑针对不同的应用程序的过程简单的Python应用程序使用此。它并不真正需要的是一个干净的解决方案,我很高兴,如果我能刚刚得到的名单产生一次,然后读了我的计划。

I'd like to use this in a simple Python application that I'm writing to simplify the process of configuring my Wacom-tablet for different applications. It doesn't really need to be a "clean" solution, I'm happy if I can just get the list produced once and then read it into my program.

我和AppleScript的摆弄过,所以如果有可能通过做AS也一定很不错。

I've fiddled with AppleScript before, so if it's possible to do it through AS that'd also be nice.

推荐答案

您可能将不得不使用GUI脚本,这意味着应用必须是开放的。我想这与Safari浏览器。如果你看看文件菜单下,第六届菜单项是具有移位CMD-W的键盘快捷键关闭窗口菜单项。我的目标是一见,如果我能得到它...

You'll probably have to use gui scripting which means the application will have to be open. I tried this with Safari. If you look under the "File" menu, the 6th menu item is the "Close Window" menu item which has a keyboard shortcut of shift-cmd-w. I targeted that one to see if I can get it...

tell application "System Events"
    tell process "Safari"
        -- get the menu bar items from the main menu
        tell menu bar 1
            set menuBarItems to menu bar items -- apple menu, application menu, file menu etc.
        end tell

        -- get the menu items from a menu bar item
        set fileMenuBarItem to item 3 of menuBarItems -- the file menu
        tell menu 1 of fileMenuBarItem -- you have to have "menu 1" here
            set menuItems to menu items
        end tell

        -- query the menu bar item
        set closeWindowMenuItem to item 6 of menuItems -- close window menu item
        tell closeWindowMenuItem
            return {name, value} of attributes
        end tell
    end tell
end tell

如果你看一下结果,有该菜单项的几个有趣的属性。它具有AXMenuItemCmdChar属性,它带给我的键盘快捷键W。因此,我们知道,CMD-W是快捷方式的一部分。存在具有1的值。这必须转变角色叫AXMenuItemCmdModifiers另一个属性。

If you look at the results, there's a couple interesting attributes of that menu item. It has the "AXMenuItemCmdChar" attribute which gives me the "w" of the keyboard shortcut. Therefore we know that "cmd-w" is part of the shortcut. Another attribute called "AXMenuItemCmdModifiers" exists with a value of 1. That must be the shift character.

因此​​,看来你能做出来。这就是我所做的一切,所以你得看看这个越来越是否需要任何其他属性决定的。您还需要添加重复循环,以便通过每一个菜单项目循环。

So it seems you can work it out. That's all I did so you'll have to look at this more and decide if any other attributes are needed. You'll also need to add repeat loops so you loop through every menu item.

一件事我注意到...如果你打开​​文件菜单和preSS的选项键,你会发现项目更改菜单。这些改变菜单项也present当你得到一个菜单栏项目的菜单项。所以你不能总是看到菜单项,你会得到的。

One thing I noticed... if you open the file menu and press the "option" key you'll notice the menu items change. Those changed menu items are also present when you get the menu items of a menu bar item. So you can't always see the menu items you will get.

这篇关于从另一个应用程序获取所有快捷键列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆