I'm trying to find a way to programatically get/set the default OSX system keyboard shortcuts (hotkeys) found in the System Preferences -> Keyboard & Mouse -> Keyboard Shortcuts tab. I need to be able to do this in the background, so GUI scripting is not a solution.
I'm unable to find a plist or anything where this info might be stored. I tried using Instruments "File Activity" trace while using System Preferences, but again came up empty handed.
Any help is appreciated.
Actually there's a Plist for that, informations are stored in
com.apple.symbolichotkeys AppleSymbolicHotKeys
which is a complex nested dicts and lists as :Let's say you want to programatically modify the "Show Help Menu" shortcut in System Preferences -> Keyboard -> Shortcuts tab -> App Shortcut -> All Applications. To find the correct entry print all the Plist in a text file, modify the shortcut in the System Preferences, print again the the Plist in a second file and diff them:
So the entry to be modified is
98
, since it's a complex structure you'll have to use/usr/libexec/PlistBuddy
to do it:Note:
bool
parameter in order to modify itOoop, I re-ran Instruments, but made sure to close out System Preferences this time, the shortcuts weren't getting written out until then.
Turns out the file is located at ~/Library/Preferences/com.apple.symbolichotkeys.plist But it's pretty cryptic. None the less, this is what I was after.
There is an API for this (getting, not setting).