macos-defaults icon indicating copy to clipboard operation
macos-defaults copied to clipboard

Automate setting a keyboard shortcut

Open schneems opened this issue 3 years ago • 2 comments

  • [x] I made sure this feature is not in the commands list
  • [x] I searched and didn't find this feature request in the listed issues

I'm looking for a command to set a keyboard shortcut on the terminal. I would like to set this as a default on all new machines https://mobile.twitter.com/techgirl1908/status/1067500256516952065. I tried running:

defaults find Keyboard | pbcopy

I recorded it after setting the keyboard shortcut manually, and then again after deleting the value and then fed both into diffchecker. The diffs were identical. Which lead me to believe that this value is not persisted in defaults.

If defaults doesn't capture this setting do you know what might? Also might it be helpful to list what preferences are not able to be set via this command?

Thanks a ton for the repo, it's been hugely helpful.

schneems avatar Sep 13 '21 20:09 schneems

Hi @schneems thanks for your message and your patience.

I think I've found out where it's located (I've used defaults read to get all keys), take a look at:

$ defaults read NSGlobalDomain NSUserKeyEquivalents

Got to make sure we can set it using command line tho.

Can you try it out and create a PR if it works? 😄

yannbertrand avatar Oct 14 '21 09:10 yannbertrand

Thanks for the reply! I am able to see those two:

$ defaults read NSUserKeyEquivalents
2021-10-14 13:35:02.300 defaults[61302:17355892]
Domain NSUserKeyEquivalents does not exist
$ defaults read NSGlobalDomain | grep mouse
    "com.apple.mouse.scaling" = "1.5";

Regarding my original use case, it turns out that doing this: https://mobile.twitter.com/techgirl1908/status/1067500256516952065 interferes in other applications in ways that are difficult to predict. For instance, in slack, I usually hit CMD+SHIFT+Enter to open a "create snippet" dialog. With that CMD+V hack, for some reason, that feature in slack became unusable. 🤷‍♀️

schneems avatar Oct 14 '21 18:10 schneems