I would like to know how I can disable ALL keyboard shortcuts via the terminal. I know you can disable them by going to:
but I want to disable them via terminal. anyone knows how this can be done?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
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
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
org.gnome.desktop.wm.keybindings unmaximize <TAB> ['<Control><Super>Down']
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
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
$kand its value into
$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.
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.
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
I built upon @terdon's answer and made a script to do the same, but does so in a somewhat more user friendly fashion.
You could use it like this:
gnome-key-bindings --unset-all --except 'close|switch-applications'
As I like using the default keybindings Alt-F4 and Alt-Tab (and their reverse using shift), this would remove all keybindings except these.
It also has a nice help menu:
List/disable/enable/set gnome-key-bindings gnome-key-bindings [-h | option] [value] Options --list Lists all the current keybindings --set=key Set a specific keybinding --unset=key Unsets a specific keybinding --unset-all Unsets all keybindings --except=REGEX Filter out keys matching REGEX from being unset --print-default Prints the default shortcuts per Ubuntu 18.04 Examples: Clearing all keys except a few: gnome-key-bindings --unset-all --except "close|switch-applications|switch-input-source|show-desktop" Setting a shortcut gnome-key-bindings --set=maximize "<Super>Up"
To use it on your own machine
curl -s https://raw.githubusercontent.com/fatso83/dotfiles/master/utils/scripts/gnome-key-bindings -o gnome-key-bindings curl -s https://raw.githubusercontent.com/fatso83/dotfiles/master/utils/scripts/easyoptions.sh -o easyoptions.sh curl -s https://raw.githubusercontent.com/fatso83/dotfiles/master/utils/scripts/easyoptions.rb -o easyoptions.rb chmod +x ./gnome-key-bindings sudo mv ./gnome-key-bindings easyoptions.* /usr/local/bin/
For gnome on Ubuntu 18.04, I found this to work:
gsettings list-keys org.gnome.shell.keybindings | xargs -I@ gsettings set org.gnome.shell.keybindings @ [''] gsettings list-keys org.gnome.mutter.keybindings | xargs -I@ gsettings set org.gnome.mutter.keybindings @ [''] gsettings list-keys org.gnome.settings-daemon.plugins.media-keys | xargs -I@ gsettings set org.gnome.settings-daemon.plugins.media-keys @ [''] gsettings set org.gnome.mutter overlay-key ''
I'm not sure if that's all the shortcut keys, but it seems to be the bulk of them