Disable ⌘+p and ⌘+s in Terminal.app
I continually hit ⌘-P and ⌘-S while Terminal is in focus, due to alt-tabbing between my text editor and other programs.
Does anyone know how to disable these keys in Terminal.app?
Solution 1:
You could try out Keymando which will let you set specific shortcuts for programs. In this case, you would set those commands to do nothing.
Another solution would be to use iTerm 2, which allows you to specify shortcuts for keys (or to ignore).
Solution 2:
Removing a Default Keyboard Shortcut in OS X
TL;DR Version
Run the following two commands in Terminal, then restart it.
defaults write com.apple.terminal NSUserKeyEquivalents -dict-add "Export Text As..." nil
defaults write com.apple.terminal NSUserKeyEquivalents -dict-add "Print..." nil
Full Explanation
You can use the defaults command to disable a built-in keyboard shortcut for an app (for a custom shortcut, just remove it from Keyboard Preferences).
To disable it, you need to know the exact name of the menu item the shortcut is associated with and the bundle identifier of the app.
To get an app's bundle identifier, run osascript -e 'id of app "AppName"'
in Terminal, replacing AppName
as appropriate.
Once you have that information, the proper command is:
defaults write BUNDLE_ID NSUserKeyEquivalents -dict-add "MENU_ITEM" nil
Followed by a restart of the app.
Restoring the Shortcuts
If you want to undo this, you can either remove the entries in Keyboard Preferences if they appear there (they don't always), or rewrite the NSUserKeyEquivalents
dictionary.
First, check if you have any other shortcuts set, by running defaults read BUNDLE_ID NSUserKeyEquivalents
.
If you only see the entries you created, then you can just run defaults delete BUNDLE_ID NSUserKeyEquivalents
and restart the app.
If there are other entries (most likely custom shortcuts you set in Keyboard Preferences), then you need to modify the entry, read below.
Selectively Restoring Default Shortcuts
Run defaults read BUNDLE_ID NSUserKeyEquivalents
. You'll get some output like this:
{
"Other Shortcut" = "@\\U2190";
"Export Text As..." = nil;
"Print..." = nil;
}
Remove the lines you want to reset (Export
and Print
), then copy the remaining output as-is; make sure to include the curly brackets. Then type (but don't yet run) defaults write BUNDLE_ID NSUserKeyEquivalents '
. Paste your modified text after that (be sure you included the single quote before pasting), then close the single quote ('
) and run the command. Once you restart the app, the default shortcuts should be restored, while keeping any existing ones.