Ubuntu – Assign multiple keyboard shortcuts for one action

keyboardshortcuts

I've been wondering how can I assign to multiple keyboard shortcuts to do the same action?
More specifically, I want to be able to change my volume with both my headset buttons and my keyboard.

I'm able to change the volume with just one at the time: with the one I define in the 'Keyboard shortcuts' application.
Is there any way?

Best Answer

You can assign multiple keyboard shortcuts (keybindings) for the same command using gsettings command line.

One important thing to know is that Ubuntu 18.04 Settings GUI only shows the first keybinding for a command, so if you have multiple keybindings for a command, the others won't appear in Settings. You can use gsettings to all the keybindings.

Let's say I want to add another keybinding for "Switch to Workspace 1". The default for me was Super+Home, but I want to add a second keybinding Ctrl+1.

# list all keybindings
gsettings list-recursively | grep -e org.gnome.desktop.wm.keybindings -e org.gnome.settings-daemon.plugins.media-keys -e org.gnome.settings-daemon.plugins.power | sort 

# confirm no other keybinding conflicts
gsettings list-recursively | grep '<Control>1'

# set multiple keybindings for "Switch to Workspace 1"
gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-1 "['<Super>Home', '<Control>1']"

# confirm value is set correctly
gsettings get org.gnome.desktop.wm.keybindings switch-to-workspace-1

Now you can use either Super+Home or Control+1 to Switch to Workspace 1. Remember, you will only see the first one Super+Home in the Settings GUI, but it will work!

Related Question