65

I would like to disable keyboard shortcuts Command-W and Command-Q in Mac OS X 10.8 Mountain Lion.

This is because they interfere with emacs commands which I run from inside a terminal running from xQuartz. How can I disable the keyboard shortcuts?

3
  • 2
    Setting->Keyboard & Mouse Preference Pane->Keyboard Shortcuts To change a shortcut, double click on the existing shortcut, and press the keys that make up your new shortcut. Commented Mar 30, 2013 at 13:41
  • 4
    Not all keyboard shortcuts show up there. Command+Q and Command+W are two examples that don't.
    – JohnGB
    Commented Jul 30, 2013 at 12:06
  • 7
    This kind of question is fitting better AskDifferent community, rather than community for developers. Voting for the move.
    – Farside
    Commented Apr 26, 2016 at 9:03

8 Answers 8

40

BetterTouchTool is no longer free.

I reached this page because I wanted to disable command-h (hide application) which is not shown in System Preferences. This is my solution.

BetterTouchTool is a utility which can disable keyboard shortcuts (and has many other uses). http://www.boastr.de/

To disable command-w globally

  1. Install BetterTouchTool
  2. Click on the BetterTouchTool menubar item and choose "Preferences"
  3. Click "Gestures"
  4. Click "Keyboard"
  5. Click "Global"
  6. Click "Add New Shortcut"
  7. Click "Keyboard Shortcut"
  8. Type the shortcut you want to disable (for example, command-w)
  9. Set Trigger Predefined Action to "No Action" (which is the default)

Note that you can also set a keyboard shortcut for a specific application.

To disable command-w only for Terminal

  1. Install BetterTouchTool
  2. Click on the BetterTouchTool menubar item and choose "Preferences"
  3. Click "Gestures"
  4. Click "Keyboard"
  5. Click the plus sign at the bottom of the "Select Application" pane
  6. Choose Terminal (in Applications/Utilities folder)
  7. Click "Add New Shortcut"
  8. Click "Keyboard Shortcut"
  9. Type the shortcut you want to disable (for example, command-w)
  10. Set Trigger Predefined Action to "No Action" (which is the default)
5
  • I already had BetterTouchTool and know about this before, but I came here also looking for answers. Thanks for reminding me
    – Endless
    Commented Aug 11, 2014 at 13:16
  • Wish this worked for me, but disabling Ctrl-Alt-F for Full Screen in VMWare Fusion did not work. Still annoyingly toggles full screen instead of acting in my Windows app as a shortcut. Commented Jul 9, 2015 at 16:24
  • 11
    BetterTouchTool is no longer free. Commented Feb 11, 2016 at 10:17
  • Works even for overriding VirtualBox, nice!
    – michel-slm
    Commented Jan 21, 2017 at 17:32
  • Since command-w has a shortcut in termanal, does it also disables that?
    – alper
    Commented May 17, 2020 at 10:17
23

BetterTouch wasn't able to change or disable the key that was causing me grief: ctrl-cmd-d.

Here is how I was able to delete it:

  1. Edit open ~/Library/Preferences/com.apple.symbolichotkeys.plist
  2. Find the code for kCGHotKeyLookUpWordInDictionary (70), and set 'enabled' to OFF (if it's not there just create an entry '70' with 'enabled' = OFF).
  3. Restart your system

From this site I learned about symbolic hot keys and found a list of them: http://www.theregister.co.uk/2009/02/24/hotkeys_framework2/

These sites have lists of the codes used in the plist file, so one can actually change the shortcuts instead of only deleting them: http://krypted.com/mac-os-x/defaults-symbolichotkeys/ and Documenting com.apple.symbolichotkeys.plist.

3
  • I tried editing ~/Library/Preferences/com.apple.symbolichotkeys.plist, but there was barely anything in it, and they were almost all already disabled. There was no shortcut 70 for example. Also, is there any way to find out the numeric code for a given shortcut?
    – Antimony
    Commented Nov 21, 2017 at 17:48
  • Use the tools suggested in this answer to easily find the code for any combination of keys.
    – sam2426679
    Commented Mar 19, 2020 at 1:24
  • That awesome. But i don't get it how i can calculate what code have shortcut that im looking for, can someone lead me more precisely?
    – bloowper
    Commented May 18 at 13:26
22

To view or change Keyboard shortcuts:

  1. Open the System Preferences->Keyboard
  2. Click on the Keyboard Shortcuts tab
  3. To change a shortcut, double click on the existing shortcut, and press the keys that make up your new shortcut.
  4. If you make a mistake, click '"Restore Defaults to return the keyboard shortcuts to the factory defaults
7
  • I am unable to do this under mountain lion -- OS X 10.8. The pane you mention doesnt seem to be there. Sorry if I am missing something obvious. Thanks.
    – Ekalavya
    Commented Mar 31, 2013 at 4:11
  • 1
    @Ekalavya not all shortcuts show up there. I think you have to edit the ~/Library/Preferences/.GlobalPreferences.plist file.
    – JohnGB
    Commented Jul 30, 2013 at 12:07
  • @JohnGB sublime text doesn't seem to be able to edit that file Commented Jun 1, 2015 at 17:23
  • @Tamil Selvan The shortcut I'm trying to disable, 'Command + Return' which makes an app go fullscreen, it's in that list of hotkeys. Commented Jun 1, 2015 at 17:24
  • 1
    @advocate You usually use Xcode.app to edit that file.
    – JohnGB
    Commented Jun 1, 2015 at 18:07
15

A solution that may work for factory hotkeys in individual apps which conflict with your desired assignment:

Use the built-in hotkey management:

System Preferences | Keyboard | Shortcuts | App Shortcuts

...to map the pre-existing to some hard-to-hit keyboard combination (like Cmd-Opt-Shift-backslash). This will free-up the old key combination for assignment.

2
  • I wanted to reuse cmd-q and cmd-, in an app, but disabling them with better touch tool would render them unusable at all. This worked nicely, thanks!
    – Norswap
    Commented Nov 16, 2016 at 13:45
  • Overriding as documented here worked for me: discussions.apple.com/thread/4410612 "Open System Preferences > click Keyboard > click Keyboard Shortcuts > click Application Shortcuts in the left panel > click the "+" button below the right panel > Select Finder as your Application: > set the menu title to exactly the case-sensative value of "Bring All to Front" > set Keyboard Shortcut to "command+p" by actually pressing the-command-key+p-key"
    – kampsj
    Commented Mar 2, 2018 at 12:53
5

Which highly recommend is hammerspoon, who defined GOD LIKE!

  1. install hammerspoon

  2. vim ~/.hammerspoon/init.lua

  3. paste this hs.hotkey.bind("cmd", 'H', function()end) in

  4. :wq and then StatusBar -> Hammerspoon -> ReloadConfig

  5. done!

Happy Hack!

1
  • When I tried this, it disabled not only the OSX system shortcut, but also the app shortcut.
    – magum
    Commented Feb 16, 2022 at 10:29
1

A solution is to configure XQuartz to enable "Option keys send Alt_L and Alt_R" under Preferences/Input.

Then add this to your ~/.emacs:

(setq x-alt-keysym 'meta)

It is not perfect, as you might still slip on Cmd-W instead of Option-W sometimes, but at least it is functional.

1

Following an article on how to script shortcuts I tried setting a shortcut to '' to no avail, but setting it to NULL worked fine. Here's an example:

TAB_KEY_SYMBOL="\\U21e5"
COMMAND_KEY_SYMBOL="@"
SHIFT_KEY_SYMBOL="$"

defaults write com.apple.finder NSUserKeyEquivalents "{ 'Show Package Contents' = '${COMMAND_KEY_SYMBOL}${SHIFT_KEY_SYMBOL}O'; }"

defaults write com.apple.finder NSUserKeyEquivalents -dict-add 'Add to Sidebar' '\U0000'
defaults write com.apple.finder NSUserKeyEquivalents -dict-add 'Add to Dock' '\U0000'

# kill finder and prefs daemon
killall Finder
killall cfprefsd

# *only* if absent, add bundle id to make it show up in keyboard prefs pane
defaults read com.apple.universalaccess "com.apple.custommenu.apps"
defaults write com.apple.universalaccess "com.apple.custommenu.apps" -array-add "com.apple.finder"

$ defaults read com.apple.finder NSUserKeyEquivalents 
{
    "Add to Dock" = "";
    "Add to Sidebar" = "";
    "Show Package Contents" = "@$O";
}
0

If you only want to disable it for a single app, you can use a null string with the NSUserKeyEquivalents preference:

defaults write org.xquartz.X11 NSUserKeyEquivalents -dict-add "Quit X11" "\0"
defaults write org.xquartz.X11 NSUserKeyEquivalents -dict-add "Close" "\0"

or

defaults write NSGlobalDomain NSUserKeyEquivalents -dict-add "Quit X11" "\0"

Then restart the app and you should see the menu bar item changed with the shortcut removed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.