0

When I tried to list the available custom keybindings using gsettings command

gsettings get org.gnome.settings-daemon.plugins.media-keys custom-keybindings

I got the error message saying,

No such key 'custom-keybindings'

I graphically checked my custom keyboard shortcuts and it was empty. So I thought this is normal. So I tried to add new keybinding using

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

Again the same error returned. I am using Ubuntu 12.04 in virtualbox. Doesn't it comes with the key custom-keybindings? How can I add a new custom-keybindingusing gsettings?

Sylvain Pineau
  • 61,564
  • 18
  • 149
  • 183
Anonymous Platypus
  • 3,730
  • 10
  • 33
  • 51
  • possible duplicate of [How to set custom keyboard shortcuts from terminal?](http://askubuntu.com/questions/597395/how-to-set-custom-keyboard-shortcuts-from-terminal) – Sylvain Pineau Mar 31 '15 at 07:33
  • This is not duplicate. I know how to set shortcuts using `gsettings`. But the problem is I cannot find the key `custom-keybindings` in Ubuntu 12.04. Is that a bug? I was able to locate it in 14.04 but not in 12.04. Where the keybinding files are actually stored in 12.04? – Anonymous Platypus Mar 31 '15 at 07:40
  • 1
    Until (and including) 12.04, custom keybindings are not stored in the `dconf` database, but in `~/.gconf/desktop/gnome/keybindings` (in subfolders like `custom0` etc). It is an xml file. See: http://askubuntu.com/a/101248/72216 – Jacob Vlijm Mar 31 '15 at 08:12
  • possible duplicate of [Where does Ubuntu store its keyboard shortcut configuration?](http://askubuntu.com/questions/101226/where-does-ubuntu-store-its-keyboard-shortcut-configuration) – Jacob Vlijm Mar 31 '15 at 08:13
  • @JacobVlijm I found that now. Thanks. So to add a new custom shortcut in Ubuntu 12.04 what I need to do is just create another folder named custom1 and place a `%gconf.xml` with settings. Am I right? – Anonymous Platypus Mar 31 '15 at 09:03
  • 1
    @AnonymousPlatypus I tried that, and it works, if the folder is named correctly, the file is correct and... after a log out / in. It can be scripted of course :) – Jacob Vlijm Mar 31 '15 at 09:11
  • Thanks a lot for the mention. I will try out and will put an answer. But there is a time parameter in that file.Those line are actually important? Is it possible to replace that unix time value with any value? – Anonymous Platypus Mar 31 '15 at 09:12
  • 1
    I added a 12.04 specific script to create custom shortcuts. – Jacob Vlijm Mar 31 '15 at 12:08

1 Answers1

1

Jacob Vlijm's python script was very useful. I am sharing a shell script to do this if someone may find it useful.

#!/bin/sh
ls -d ~/.gconf/desktop/gnome/keybindings/*/
    if [[ `echo $?` == 2 ]]; then
        shortCutNumber=0
        else
        shortCutNumber=$((`ls -d ~/.gconf/desktop/gnome/keybindings/*/ | tail -c 3 | head -c 1`+1))
    fi
    echo -e '<?xml version="1.0"?>' > %gconf.xml 
    echo -e '\t<gconf>' | tee -a %gconf.xml 
    echo -e '\t<entry name="action" mtime="`date +%s`" type="string">' | tee -a %gconf.xml 
    echo -e '\t\t<stringvalue>gnome-terminal -e '`pwd`/LanChat.sh'</stringvalue>' | tee -a %gconf.xml 
    echo -e '\t</entry>' | tee -a %gconf.xml 
    echo -e '\t<entry name="name" mtime="`date +%s`" type="string">' | tee -a %gconf.xml 
    echo -e '\t\t<stringvalue>QryptoChat</stringvalue>' | tee -a %gconf.xml 
    echo -e '\t</entry>' | tee -a %gconf.xml
    echo -e '\t<entry name="binding" mtime="`date +%s`" type="string">' | tee -a %gconf.xml 
    echo -e '\t\t<stringvalue>&lt;Alt&gt;q</stringvalue>' | tee -a %gconf.xml 
    echo -e '\t</entry>' | tee -a %gconf.xml 
    echo -e '</gconf>' | tee -a %gconf.xml 
    mkdir ~/.gconf/desktop/gnome/keybindings/custom$shortCutNumber
    mv %gconf.xml ~/.gconf/desktop/gnome/keybindings/custom$shortCutNumber/

The script first checks whether there exists any custom shortcuts already. And then creates the %gconf.xml file inside a new custom folder with the necessary settings.

Anonymous Platypus
  • 3,730
  • 10
  • 33
  • 51