Disable all Unity keyboard shortcuts using the command line
Solution 1
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
-
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']
-
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.
-
-
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
Solution 2
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/
Related videos on Youtube
user278551
Updated on September 18, 2022Comments
-
user278551 over 1 year
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?
-
terdon about 10 yearsWhat keyboard shortcuts are you talking about? There are very many different sets. You have some that work on the command line, some that activate GUI stuff etc. They are completely separate.
-
terdon about 10 yearsOK, so you mean only the GUI shortcuts. I assume you are using the default Ubuntu so your desktop environment is Unity. Is that correct?
-
user278551 about 10 yearsyes that is correct.
-
-
user.dz about 10 yearsThank you great work, I think still missing Compiz shortcuts?
-
terdon about 10 years@Sneetsher part B. should deal with the user-defined compiz shortcuts. Not sure about the default ones. Let me check.
-
oligofren almost 6 yearsAdded a script to be a little bit more of a usable front-end to do the above: github.com/fatso83/dotfiles/blob/master/utils/scripts/…
-
oligofren almost 6 yearsRegarding the "I have no idea why you would want to do this" the use case for everyone on my dev team is that the default shortcuts overlap with known key bindings in popular programs. In our case, most of the IntelliJ shortcuts didn't work, and we all really just need a handful of the Gnome shortcuts (like Alt-Tab and window resizing).
-
terdon almost 6 years@oligofren sure, but why would you then need to disable all shortcuts from the terminal? That's what I found strange. But anyway, to each their own :)
-
oligofren almost 6 yearsJust because it's tedious to go through each and every one and disable them manually in the GUI (if they are accessible at all). After the first guy complained we tried finding a faster way, hence finding your answer :-)