How to add custom keybindings with gsettings (cli)

gumbeto
  6 years ago
  0

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 org.gnome.settings-daemon.plugins.media-keys custom-keybindings


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


  $ gsettings set org.gnome.settings-daemon.plugins.media-keys 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 org.gnome.settings-daemon.plugins.media-keys custom-keybindings "['.../custom1/', '.../custom2/', '.../custom3/']"
 

 

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


  $ gsettings set ...media-keys.custom-keybinding:.../media-keys/custom-keybindings/custom3/ name "<name>"


  3.2 - Add the command:
  $ gsettings set ...media-keys.custom-keybinding:.../media-keys/custom-keybindings/custom3/ command "<command>"


  3.3 - Add the binding:


  $ gsettings set ...media-keys.custom-keybinding:.../media-keys/custom-keybindings/custom3/ binding "<binding>"
 

 

 

 

Comments
tonywhelan 1 year ago

For Mint 18 the keybindings schema is a little different. This is what I used to bind my script toggle-nemo.sh 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/.toggle-nemo.sh'
gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom0/ name 'Toggle Nemo Columns in List View'


tonywhelan 5 years ago

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


tonywhelan 5 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 5 years ago


tonywhelan
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:
http://askubuntu.com/questions/425730/how-to-add-a-key-to-an-empty-schema/428869#428869

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/.toggle-nemo.sh'
gsettings set org.cinnamon.keybindings.custom-keybinding:/org/cinnamon/keybindings/custom-keybindings/custom0/ name 'Toggle Nemo Columns in List View'


sisteczko 6 years ago

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