See also: How to script a global keyboard shortcut in MacOS
I like to maintain some scripts I use to set up new Macs the way I like them. One thing I would like to automate is the setting of some keyboard shortcuts — such as changing the Safari "Quit" command from ⌘Q to ⌥⌘Q.
Per advice here, I tried running the following in the Terminal:
defaults write com.apple.safari NSUserKeyEquivalents -dict-add "Quit Safari" -string "@~q"
However, quitting and re-opening Safari and System Preferences shows no difference after running the above command, although it appears to have worked if you look at the output of defaults read com.apple.safari
.
Using the UI under System Preferences → Keyboard → Shortcuts works as expected, causing the Quit Safari menu item to gain a modified keyboard shortcut.
How can I successfully script this change?
-app Safari
instead ofcom.apple.safari
. And make sure Safari is quit before you run the command.