How to disable keyboard shortcuts in Mac OS X? - macos

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?

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
Install BetterTouchTool
Click on the BetterTouchTool menubar item and choose "Preferences"
Click "Gestures"
Click "Keyboard"
Click "Global"
Click "Add New Shortcut"
Click "Keyboard Shortcut"
Type the shortcut you want to disable (for example, command-w)
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
Install BetterTouchTool
Click on the BetterTouchTool menubar item and choose "Preferences"
Click "Gestures"
Click "Keyboard"
Click the plus sign at the bottom of the "Select Application" pane
Choose Terminal (in Applications/Utilities folder)
Click "Add New Shortcut"
Click "Keyboard Shortcut"
Type the shortcut you want to disable (for example, command-w)
Set Trigger Predefined Action to "No Action" (which is the default)

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:
Edit open ~/Library/Preferences/com.apple.symbolichotkeys.plist
Find the code for kCGHotKeyLookUpWordInDictionary (70), and set 'enabled' to OFF
(if it's not there just create an entry '70' with 'enabled' = OFF).
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.

To view or change Keyboard shortcuts:
Open the System Preferences->Keyboard
Click on the Keyboard Shortcuts tab
To change a shortcut, double click on the existing shortcut, and
press the keys that make up your new shortcut.
If you make a mistake, click '"Restore Defaults to return the
keyboard shortcuts to the factory defaults

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.

Which highly recommend is hammerspoon, who defined GOD LIKE!
install hammerspoon
vim ~/.hammerspoon/init.lua
paste this hs.hotkey.bind("cmd", 'H', function()end) in
:wq and then StatusBar -> Hammerspoon -> ReloadConfig
done!
Happy Hack!

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.

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";
}

Related

How to define a shortcut key for opening a terminal in Mac OS [duplicate]

One of my primary tools used for programming is my Terminal. It makes my programming process more efficient when I'm able to quickly open a Terminal window.
In Ubuntu, I was using (window+Alt+T) to open Terminal. But now I use a Macbook at my programming job.
Sometimes I use Spotlight to search "Terminal", and press Enter.
I'd like to know if I can assign a keyboard hotkey to do it.
I tested the following procedure under macOS Mojave 10.14.6 (18G3020).
Launch Automator. Create a document of type “Quick Action”:
(In older versions of macOS, use the “Service” template.)
In the new Automator document, add a “Run AppleScript” action. (You can type “run applescript” into the search field at the top of the action list to find it.) Here's the AppleScript to paste into the action:
on run {input, parameters}
tell application "Terminal"
if it is running then
do script ""
end if
activate
end tell
end run
Set the “Workflow receives” popup to “no input”. It should look like this overall:
Save the document with the name “New Terminal”. Then go to the Automator menu (or the app menu in any running application) and open the Services submenu. You should now see the “New Terminal” quick action:
If you click the “New Terminal” menu item, you'll get a dialog box:
Click OK to allow the action to run. You'll see this dialog once in each application that's frontmost when you use the action. In other words, the first time you use the action while Finder is frontmost, you'll see the dialog. And the first time you use the action while Safari is frontmost, you'll see the dialog. And so on.
After you click OK in the dialog, Terminal should open a new window.
To assign a keyboard shortcut to the quick action, choose the “Services Preferences…” item from the Services menu. (Or launch System Preferences, choose the Keyboard pane, then choose the Shortcuts tab, then choose Services from the left-hand list.) Scroll to the bottom of the right-hand list and find the New Terminal service. Click it and you should see an “Add Shortcut” button:
Click the button and press your preferred keyboard shortcut. Then, scratch your head, because (when I tried it) the Add Shortcut button reappears. But click the button again and you should see your shortcut:
Now you should be able to press your keyboard shortcut in most circumstances to get a new terminal window.
As programmers we want the quickest, most fool-proof way to get our tools in order so we can start hacking. Here are how I got it to work in MacOS 10.13.1 (High Sierra):
Option 1: Go to System Preferences | Keyboard | Shortcut | Services.
Under Files and Folders section, enable New Terminal at Folder
and/or New Terminal Tab at Folder and assign a shortcut key to it.
Option 2: If you want the shortcut key to work anywhere, create a new Service using Automator, then go to the Keyboard Shortcut to assign a shortcut key to it. Known limitation: not work from the desktop
Notes:
If the shortcut doesn't work, it might be in conflict with another
key binding (and the OS wouldn't warn you), try something else, e.g.
if ⇧⌥T doesn't work, try ⇧⌘T.
Don't spell-correct MacOS, that's not necessary.
iTerm2 - an alternative to Terminal - has an option to use configurable system-wide hotkey to show/hide (initially set to Alt+Space, disabled by default)
There is a third party app called hotkey app which can launch apps based on the configured shortcuts.
You can install it and setup required shortcut.
https://codenuts.de/en/posts/hotkey/
As others mentioned already, use the keyboard shortcut from services. I also had to restart the computer to take into effect.
mac - "command + t" will open a new terminal window.
Try command + t.
It works for me.

Is there a keyboard shortcut (hotkey) to open Terminal in macOS?

One of my primary tools used for programming is my Terminal. It makes my programming process more efficient when I'm able to quickly open a Terminal window.
In Ubuntu, I was using (window+Alt+T) to open Terminal. But now I use a Macbook at my programming job.
Sometimes I use Spotlight to search "Terminal", and press Enter.
I'd like to know if I can assign a keyboard hotkey to do it.
I tested the following procedure under macOS Mojave 10.14.6 (18G3020).
Launch Automator. Create a document of type “Quick Action”:
(In older versions of macOS, use the “Service” template.)
In the new Automator document, add a “Run AppleScript” action. (You can type “run applescript” into the search field at the top of the action list to find it.) Here's the AppleScript to paste into the action:
on run {input, parameters}
tell application "Terminal"
if it is running then
do script ""
end if
activate
end tell
end run
Set the “Workflow receives” popup to “no input”. It should look like this overall:
Save the document with the name “New Terminal”. Then go to the Automator menu (or the app menu in any running application) and open the Services submenu. You should now see the “New Terminal” quick action:
If you click the “New Terminal” menu item, you'll get a dialog box:
Click OK to allow the action to run. You'll see this dialog once in each application that's frontmost when you use the action. In other words, the first time you use the action while Finder is frontmost, you'll see the dialog. And the first time you use the action while Safari is frontmost, you'll see the dialog. And so on.
After you click OK in the dialog, Terminal should open a new window.
To assign a keyboard shortcut to the quick action, choose the “Services Preferences…” item from the Services menu. (Or launch System Preferences, choose the Keyboard pane, then choose the Shortcuts tab, then choose Services from the left-hand list.) Scroll to the bottom of the right-hand list and find the New Terminal service. Click it and you should see an “Add Shortcut” button:
Click the button and press your preferred keyboard shortcut. Then, scratch your head, because (when I tried it) the Add Shortcut button reappears. But click the button again and you should see your shortcut:
Now you should be able to press your keyboard shortcut in most circumstances to get a new terminal window.
As programmers we want the quickest, most fool-proof way to get our tools in order so we can start hacking. Here are how I got it to work in MacOS 10.13.1 (High Sierra):
Option 1: Go to System Preferences | Keyboard | Shortcut | Services.
Under Files and Folders section, enable New Terminal at Folder
and/or New Terminal Tab at Folder and assign a shortcut key to it.
Option 2: If you want the shortcut key to work anywhere, create a new Service using Automator, then go to the Keyboard Shortcut to assign a shortcut key to it. Known limitation: not work from the desktop
Notes:
If the shortcut doesn't work, it might be in conflict with another
key binding (and the OS wouldn't warn you), try something else, e.g.
if ⇧⌥T doesn't work, try ⇧⌘T.
Don't spell-correct MacOS, that's not necessary.
iTerm2 - an alternative to Terminal - has an option to use configurable system-wide hotkey to show/hide (initially set to Alt+Space, disabled by default)
There is a third party app called hotkey app which can launch apps based on the configured shortcuts.
You can install it and setup required shortcut.
https://codenuts.de/en/posts/hotkey/
As others mentioned already, use the keyboard shortcut from services. I also had to restart the computer to take into effect.
mac - "command + t" will open a new terminal window.
Try command + t.
It works for me.

How to preserve iTerm folder location between sessions?

I'm using iTerm 2, and each time I exit and launch it again it doesn't save the folder location I was working on.
This is really annoying to have to retype each time the previous location I was working on, event more when there were multiple tabs opened...
Is there a way so that iTerm automatically save the folder path for each tab when I exit ?
iTerm 2.9.x (currently beta) and above support restoring sessions like the default Terminal.app in OS-X.
http://iterm2.com/downloads.html
https://gitlab.com/gnachman/iterm2/issues/3717#note_1733467
On macOS, make sure to uncheck "Close windows when quitting app" in the System Preferences/General tab (note this is in the System Preferences, not in the iTerm2 preferences).
Also set the following iTerm2 settings in the iTerm2 preferences:
General tab: select Use System Window Restoration Setting
General tab: uncheck Open profiles Window
General tab: uncheck Confirm closing multiple sessions
General tab: Confirm "Quit iTerm2 (⌘Q)" command
Advanced tab: Restore Window contents at startup = Yes

How to change the key binding of "Go to File" of textmate?

I want to change the key binding of "Go to File" of textmate from it's default one Cmd + T to option + cmd + n. How to do that?
Head into System Preferences → Keyboard → Shortcuts → App Shortcuts.
Add a new Application (Textmate) and the Menu Title should be 'Go to File..."
I tried just using 'Go to File' but found out the actual title requires the additional '...'
Go to System Preferences → Keyboard → Shortcuts.
Click App Shortcuts and then the plus button to create a new entry.
Select TextMate as application, set menu title to Go to File… (including the ellipsis) and then pick your desired key equivalent.

Launch default editor in Xcode

I've configured MacVim to be my default editor in Xcode. I can invoke it from Xcode by double clicking the file in the project view. Is there any keyboard shortcut I can configure or invoke to open the file being viewed in the Xcode editor in my default configured editor?
I am using Xcode 4.3. You can assign a shortcut to open the file in an external editor using the menu item File/Open with External Editor. To assign the shortcut you will need to go to System Preferences/Keyboard/Keyboard Shortcuts, choose Applications Shortcuts, click on the plus button, choose Xcode from the drop down menu, write 'Open with External Editor' in the Menu Title field and choose your shortcut.
Try Option-Command-O - if that doesn't work then you may need to go to Key Bindings in Preferences and set it up (I use the BBEdit Compatible key bindings which include this shortcut as standard).
I made a little write up here fwiw:
https://tmsh.github.io/visual-guide-opening-files-externally-xcode/

Resources