0

I'm used to have some keyboard shortcut remapping for menu items via Apple's system preferences -> keyboard pane. Some globals, most of them application specific.

What was working in the past (High Sierra if I'm not mistaken) was something like this:

defaults write com.googlecode.iterm2 NSUserKeyEquivalents -dict-add "Advanced Paste…" -string "@~^v"

Running

defaults read com.googlecode.iterm2 NSUserKeyEquivalents

shows that it has been set, but neither System Preferences (after restart) shows it nor the menu item in iTerm2.

If I enter it manually in System Preferences, the read command reveals the same (after deleting it before) and the new shortcut is visible in the menu.

This seems to be the case on Catalina for every application and shortcut I previously added via a setup script, e.g. for apps like Safari, Google Chrome, etc.

I also tried

defaults write -app iTerm ...

but it has the exact same effect.

Did anything change on (at least) Catalina? What's the correct way nowadays to do it?

1

Figured it out. You have to add the application you want to modify keys for to com.apple.universalaccess.

defaults write com.apple.universalaccess com.apple.custommenu.apps -array-add "com.googlecode.iterm2"

or if all keyboard equivalents are set via one file, you can also write the full list at once

defaults write com.apple.universalaccess com.apple.custommenu.apps -array "com.googlecode.iterm2" "com.apple.Safari" "com.google.Chrome"

The other thing that was tricky was, that my iterm2 prefs file is symlinked and therefore doesn't appear in the list of domains nor is read with the defaults tool. The keyboard however works, since it's listed in the prefs file already.

| improve this answer | |
  • Is there a file to add to universal access for global shortcuts (i.e. defaults write -g NSUserKeyEquivalents ...), because those aren't being added for me for various services menu items I want to create shortcuts for... – hepcat72 Oct 9 at 13:55
  • It's also notable that all the keyboard shortcut commands I ran via my script before adding a single app (Text Edit) to universal access, got activated after adding Text Edit. I.e. all my menu items and apps showed up in the shortcuts in system preferences for various apps but none of them had shortcut keys shown. I only added text edit as you suggested and then I checked system preferences and EVERY shortcut for EVERY app I'd added previously now have the shortcuts I'd set. Seems like a security flaw. – hepcat72 Oct 9 at 13:59
  • That is of course, except for the global ones... :( – hepcat72 Oct 9 at 14:01
  • OK. I got it: defaults write com.apple.universalaccess com.apple.custommenu.apps -array-add NSGlobalDomain – hepcat72 Oct 9 at 14:09
  • Though I should note, a shortcut apparently will not work in all apps until those apps that were running when the command was issued have been restarted. – hepcat72 Oct 9 at 14:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .