Ubuntu – Disable all Unity keyboard shortcuts using the command line

command lineshortcut-keys

I would like to know how I can disable ALL keyboard shortcuts via the terminal.
I know you can disable them by going to:

system settings>keyboard>shortcuts

but I want to disable them via terminal. anyone knows how this can be done?

Best Answer

I have no idea why you would want to do this and I should warn you that it may well be complicated to get the shortcuts back. If this is really what you want to do, the commands below will disable all keyboard shortcuts. Both those set up through Unity's GUI and any you might have set up using ccsm

A. Disable the Unity keyindings

  1. First make a backup of the current bindings so you can re-enable them later

    gsettings list-recursively org.gnome.desktop.wm.keybindings | 
       perl -pe 's/(.*)\s*(\[.*?\])\s*$/$1\t$2\n/' | 
        while IFS=$'\t' read -r key val; do echo -e "$key\t$val"; done > old_settings
    

    This will create a file called old_settings in the following format:

    schema key <TAB> value
    

    For example:

    org.gnome.desktop.wm.keybindings unmaximize <TAB> ['<Control><Super>Down']
    
  2. Now disable the shortcuts

    gsettings list-recursively org.gnome.desktop.wm.keybindings | 
        perl -pe 's/(.*)\s*(\[.*?\])\s*$/$1\t$2\n/' | 
            while IFS=$'\t' read -r key val; do gsettings set $key ['']; done
    

    Explanation

    • gsettings list-recursively org.gnome.desktop.wm.keybindings : this lists all keybindings and their current values
    • perl -pe 's/(.*)\s*(\[.*?\])\s*$/$1\t$2\n/' : this simply adds a TAB character (\t) separating the value from the key. This step is needed to be able to read them properly in the next one.
    • while IFS=$'\t' read -r key val : go through each line and read the key into $k and its value into $val. $IFS=$'\t' means split on tabs so that the key and value are read correctly.
    • gsettings set $key [''] : this actually sets the value to blank, effectively disabling your shortcuts.

    Note that you may have to log out and log back in again for this to take effect.

  3. Get (some of) your shortcuts back

    while IFS=$'\t' read -r key val; do 
        gsettings set "$key" "$val"
    done < old_settings 
    

    WARNING: This will probably not work for all settings since some of them seem to have an extra parameter @as in the key name and I don't know how to deal with that one. As I said, this is all not a very good idea.

B. Disable your custom shortcuts set in ccsm

gsettings set org.gnome.settings-daemon.plugins.media-keys active false

This time, getting them back is easy. All you need to do is run

gsettings set org.gnome.settings-daemon.plugins.media-keys active true
Related Question