Tuesday, May 23, 2017

Editing Mac keybindings on the command line

This sets the "Set Print Area" command on Excel to 'Cmd-Shift-Alt-Ctrl-k'

defaults delete com.microsoft.Excel NSUserKeyEquivalents -dict-add "Set Print Area" -string "@$~^k"

It does work, but you get cramps in your fingers.

You can delete all keybindings in an app with

defaults delete com.microsoft.Excel NSUserKeyEquivalents

I can't seem to delete only one keybinding.

Listing keybindings works like this:

defaults read com.microsoft.Excel NSUserKeyEquivalents

which will give you:

{
    "Set Print Area" = "@$~^k";
}

and in case you can't find your app

defaults domains|perl -lpe "s/\, /\n/g"

will neatly list all the domains and

defaults find NSUserKeyEquivalents

will list all the user keybindings

Sources: