Carbon - Get labels for CopySymbolicHotkeys?

Viewed 167

This answer about CopySymbolicKeys() gets you the keyboard combinations for System Shortcuts in OS X, but is there any way to get at the labels associated with those combinations?

For example, I can get ⌥⌘D from CopySymbolicKeys() but I want to get "Turn Dock Hiding On/Off", its associated label in System Preferences > Keyboard > Shortcuts.

I'm think it's unlikely, but remain hopeful.

1 Answers

As far as I know, there is no API for that, but it is possible to reconstruct what you want but that will need some work from you.

You can get the names of the symbolic keys here:

/System/Library/PreferencePanes/Keyboard.prefPane/Contents/Resources/en.lproj/DefaultShortcutsTable.xml

You need to parse this XML file and then find the corresponding hotkey here:

~/Library/Preferences/com.apple.symbolichotkeys.plist

The matching must be done between key sybmolichotkey (yes, the key is misspelled like that!) in the aforementioned XML file with key called key containing the same number in the latter plist file.

Example taken from the DefaultShortcutsTable.xml file:

<dict>
        <key>name</key>
        <string>DO_NOT_LOCALIZE: Dashboard and Dock</string>
        <key>ax_description</key>
        <string>DO_NOT_LOCALIZE: Dashboard and Dock shortcuts (AX_DESCRIPTION)</string>
        <key>identifier</key>
        <string>dock</string>
        <key>iconname</key>
        <string>category_dock</string>
        <key>icon-bundle-path</key>
        <string>/System/Library/CoreServices/Dock.app</string>
        <key>canRestoreDefaults</key>
        <true/>
        <key>elements</key>
        <array>
            <dict>
                <key>name</key>
                <string>DO_NOT_LOCALIZE: Turn Dock Hiding On/Off</string>
                <key>key</key>
                <integer>2</integer>
                <key>modifier</key>
                <integer>1572864</integer>
                <key>sybmolichotkey</key>  <--- look for this key
                <integer>52</integer>      <--- and its value
                <key>charKey</key>
                <integer>100</integer>
            </dict>
            <dict>
                <key>name</key>
                <string>DO_NOT_LOCALIZE: Show Launchpad</string>
                <key>key</key>
                <integer>65535</integer>
                <key>modifier</key>
                <integer>0</integer>
                <key>sybmolichotkey</key>  <--- look for this key
                <integer>160</integer>     <--- and its value
            </dict>
        </array>
    </dict>

And then look for the same number in com.apple.symbolichotkeys.plist:

    <key>52</key>
    <dict>
        <key>enabled</key>
        <true/>
        <key>value</key>
        <dict>
            <key>parameters</key>
            <array>
                <integer>65535</integer>
                <integer>2</integer>
                <integer>1572864</integer>
            </array>
            <key>type</key>
            <string>standard</string>
        </dict>
    </dict>

Major caveat: the latter plist is in binary form. To convert it to text, you need to do this in Terminal:

plutil -convert xml1 ~/Library/Preferences/com.apple.symbolichotkeys.plist 
Related