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?

  • Try using -app Safari instead of com.apple.safari. And make sure Safari is quit before you run the command.
    – benwiggy
    Commented Mar 22, 2022 at 21:33
  • Hi @alan-h did you ever get this to work? I tried the same but didn't get it to work. Setting up the shortcut via System Preferences works flawlessly though.
    – tobias
    Commented Nov 19, 2022 at 3:22
  • No such luck, @tobias.
    – Alan H.
    Commented Jan 2, 2023 at 0:44


You must log in to answer this question.

Browse other questions tagged .