In applescript, how can I access the keyboard shortcut of a menu item?

I am trying to figure out the key combination (e.g. shift + cmd + S) of a given menu item in Applescript. The "probe menu bar" script helped me access the menu items and even check their properties, etc., but I could not find which one would print the key combination.

The probe script is as follows:

tell process "Finder"
get every menu bar
tell menu bar 1
get every menu bar item
get every menu of every menu bar item
get every menu item of every menu of every menu bar item

So I need a way to print / assemble a shortcut from the specified “menu item” during this cycle.

Thank you for your help!

+3
source share
1 answer

It appears that key usage information is available as attributes of each menu item:

tell application "System Events"
    get name of menu item 2 of menu 3 of menu bar 1 of process "Finder"
        --> "New Folder"
    get every attribute of menu item 2 of menu 3 of menu bar 1 of process "Finder"
           --> {attribute "AXRole" of menu item "New Finder Window" of menu "File" of menu bar item "File" of menu bar 1 of application process "Finder", [...]
    get properties of attribute "AXMenuItemCmdChar" of [...]
        --> {value:"N", class:attribute, settable:false, name:"AXMenuItemCmdChar"}
    get properties of attribute "AXMenuItemCmdModifiers" of [...]
    --> {value:1, class:attribute, settable:false, name:"AXMenuItemCmdModifiers"}

.

+6

Source: https://habr.com/ru/post/1722228/


All Articles