How to add custom keybindings with gsettings (cli)

  9 years ago

I had some problems with custom keyboard shortcuts after copying my settings from a different machine where I had installed cinnamon over linux mint cinnamon edition. It took me a good while to figure out how to get my shortcuts to work, so I figured I would share here.

## To add a custom keybinding

1 - Obtain the current custom shortcut list:

$ gsettings get custom-keybindings

2 -
  2a) If the list obtained in the previous step was empty -> Put a custom path in the list:

  $ gsettings set custom-keybindings "['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/']"

  2b) Else -> extend the list. Suppose the obtained value was ['.../custom1/', '.../custom2/']. Do:

$ gsettings set custom-keybindings "['.../custom1/', '.../custom2/', '.../custom3/']"


3 - Add the keybinding entry:
  3.1 - Add the name:

  $ gsettings set name "<name>"

  3.2 - Add the command:
  $ gsettings set command "<command>"

  3.3 - Add the binding:

  $ gsettings set binding "<binding>"




tonywhelan 4 years ago

For Mint 18 the keybindings schema is a little different. This is what I used to bind my script tothe Super N key:
gsettings set org.cinnamon.desktop.keybindings custom-list "['custom0']" # custom keybindings path
gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom0/ binding "['n']" # Make 'Super n' the toggle key
gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom0/ command '/home/your-username/'
gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom0/ name 'Toggle Nemo Columns in List View'

tonywhelan 8 years ago

I should have said that my code below worked ok on Mint 16

tonywhelan 8 years ago

In the third last line of my comment, i.e.:
gsettings set org.cinnamon.keybindings.custom-keybinding:/org/cinnamon/keybindings/custom-keybindings/custom0/ binding 'n'

the word Primary in angle-brackets should precede the final two characters (n') but the blog software deletes it (presumably thinks it is a html tag)

tonywhelan 8 years ago

I had a hard time doing something similar. I wanted to change the Ctrl N key from launching Nemo, to instead running a little script that toggled the columns Nemo displays. I found a useful hint from @Donarsson here:

This is what I ended up with:
# To retrieve Cinnamon custom keybindings in Linux Mint Cinnamon:
gsettings get org.cinnamon.keybindings custom-list
# (note first instance below of 'custom-keybinding' does not have an 's' on end;
# if you include the 's', you'll get an error. )
gsettings get org.cinnamon.keybindings.custom-keybinding:/org/cinnamon/keybindings/custom-keybindings/custom0/ binding
gsettings get org.cinnamon.keybindings.custom-keybinding:/org/cinnamon/keybindings/custom-keybindings/custom0/ command
gsettings get org.cinnamon.keybindings.custom-keybinding:/org/cinnamon/keybindings/custom-keybindings/custom0/ name

To set custom keybindings:
gsettings set org.cinnamon.keybindings custom-list "['custom0']"
gsettings set org.cinnamon.keybindings.custom-keybinding:/org/cinnamon/keybindings/custom-keybindings/custom0/ binding 'n'
gsettings set org.cinnamon.keybindings.custom-keybinding:/org/cinnamon/keybindings/custom-keybindings/custom0/ command '/home/your-user-name/'
gsettings set org.cinnamon.keybindings.custom-keybinding:/org/cinnamon/keybindings/custom-keybindings/custom0/ name 'Toggle Nemo Columns in List View'

sisteczko 9 years ago

It doesn't work on Mint 16 Cinnamon...