32

Where can I access OS X keyboard shortcuts, say for Dropbox sync?

Allan
  • 101,432
Chauncey Garrett
  • 1,039
  • 2
  • 8
  • 19

4 Answers4

37

The shortcuts that can be set in System Preferences > Keyboard > Shortcuts > App Shortcuts are stored in ~/Library/Preferences/.GlobalPreferences.plist and the property lists of applications (like ~/Library/Preferences/com.apple.iTunes.plist or ~/Library/Containers/com.apple.chess/Data/Library/Preferences/com.apple.chess.plist).

The shortcuts for services are stored in ~/Library/Preferences/pbs.plist.

Lucas
  • 249
Lri
  • 105,117
  • I wonder if I'm the only person this didn't work for. These files also don't seem to be the XML files that I'd expect - they seem to have some binary or something... – Ben Creasy Nov 27 '16 at 19:17
  • same, don't work for me (macOS Sierra 10.12.2) – milushov Jan 09 '17 at 01:54
  • 6
    This appeared as binary for me as well. But then use the command plutil -convert xml1 .GlobalPreferences.plist to convert it to XML, and plutil -convert binary1 .GlobalPreferences.plist to convert it back. Source: https://discussions.apple.com/thread/1768480?tstart=0 – Jay Jan 16 '17 at 21:05
  • 2
    Also, TextWrangler can open binary plist files. – Jay Sep 18 '17 at 18:17
  • You can use https://apps.apple.com/us/app/plist-editor/id1157491961?mt=12 to edit the file easily (binary) but I also don't see keyboard shortcuts in this file... – aubreypwd Oct 14 '20 at 16:15
  • Looking at http://aubrey.pw/d/2020/1602692656.png it looks like the shortcuts for each app is actually stored in their own respective .plist file. But, maybe global shortcuts are stored in .Globa... file. – aubreypwd Oct 14 '20 at 16:25
  • My last comment is maybe false, as I found the keyboard shortcut e.g. for Harvest was in ~/Library/Preferences/com.getharvest.harvestxapp.plist - http://aubrey.pw/d/2020/1602693929.png – aubreypwd Oct 14 '20 at 16:45
  • 4
    Also you can use sudo opensnoop | grep '.plist' while editing shortcuts to see what .plist files have been modified. – aubreypwd Oct 14 '20 at 16:46
  • 2
    I found out that as of Catalina an app section in System Preferences > Keyboard > Shortcuts > App Shortcuts has to be created first. Otherwise, the system doesn't see the shortcuts defined in .plist (e.g. copied over from elsewhere). Once you create a section e.g. with a dummy shortcut, the .plist can be copied over and it takes effect fine. – Dima Korobskiy May 19 '21 at 22:50
11

As described in the accepted answer, you can determine an app's shortcuts by converting the plist to xml and then parsing the xml. You can also (tested on macOS Sierra 10.12.6) get the values directly with the defaults read command.

To write out the user key commands that apply in all applications run defaults read NSGlobalDomain NSUserKeyEquivalents:

$ defaults read NSGlobalDomain NSUserKeyEquivalents
{
    "Enter Full Screen" = "@^f";
    "Exit Full Screen" = "@^f";
    "Merge All Windows" = "@$m";
}

To write out the user keyboard shortcuts for a particular app, use defaults read <app-plist-name> NSUserKeyEquivalents. For example, to get the user keyboard shortcuts for Safari run (in this example, the user hasn't set any custom keyboard shortcuts for Safari)

$ defaults read com.apple.safari NSUserKeyEquivalents
The domain/default pair of (com.apple.safari, NSUserKeyEquivalents) does not exist

Key mappings I have discovered in this string syntax:

  • command = @
  • control = ^
  • option = ~
  • shift = $
3

This command will print the keyboard shortcuts along with the prefix required to set them:

printf "defaults write NSGlobalDomain NSUserKeyEquivalents '$(defaults read NSGlobalDomain NSUserKeyEquivalents)'"

For an app like Safari, run:

printf "defaults write -app Safari NSUserKeyEquivalents '$(defaults read -app Safari NSUserKeyEquivalents)'"

Those commands will output something like: defaults write [...] NSUserKeyEquivalents '{...}', which can then be used in a shell script

neovr
  • 31
  • 3
2

I don't know about later OS versions but on macOS 10.13 High Sierra (and recognised from earlier versions), apart from what the accepted answer says and likely needed after neovr's answer, there's also the ~/Library/Preferences/com.apple.universalaccess.plist key com.apple.custommenu.apps used by System Preferences's user interface to show applications with set shortcuts.


I had an application that had modified shortcuts but it wasn't showing in System Preferences's user interface (because I had copied the app plist from a backup into ~/Library/Preferences), so I did following.
Type any command line code on your keyboard or copy and paste it after starting bash in Terminal (actually I'm using iTerm). Hit the return or enter key on your keyboard after any ; (semicolon).

  1. Quit System Preferences

  2. Store a CFBundleIdentifier

    • If you know the CFBundleIdentifier you can type it in or paste it after CFBundleIdentifier= and hit enter or return on your keyboard.
    • Otherwise:
      1. Store a pathToTheApplication.

        You can type the filesystem path after pathToTheApplication=/ using your keyboard, optionally completing partial paths with one or two hits on the tab key,
        or by other means:

        1. pathToTheApplication= - don't type return or enter on your keyboard yet.
        2. Drag and drop the application from the Finder into the Terminal.
        3. Type return or enter on your keyboard.
      2. CFBundleIdentifier=$(defaults read "$pathToTheApplication"/Contents/Info CFBundleIdentifier);

  3. /usr/libexec/PlistBuddy -c "add :com.apple.custommenu.apps: string \"$CFBundleIdentifier\"" ~/Library/Preferences/com.apple.universalaccess.plist; - I made a backup copy of the plist first cause I haven't got a working TimeMachine.

  4. killall cfprefsd; - this will restart a background daemon, updating any changed preferences plists from the filesystem.

  5. Open System Preferences


Other useful command lines:

  • To see the current list of applications used in the System Preferences's user interface:
    defaults read com.apple.universalaccess com.apple.custommenu.apps
  • To find other apps having keyboard shortcuts set:
    defaults find NSUserKeyEquivalents
vike
  • 131