How to set custom keyboard shortcuts from terminal for different Linux versions?
Basically I want to know where Linux stores the keyboard shortcut files and how it can be edited.
On my research I found a file ~/.config/compiz-1/compizconfig
but it was more or like encrypted when I tried to open it with nano
.
Best Answer
Adding shortcut keybindings in two steps from the command line (14.04+)
Adding custom shortcuts from the command line can be done, but is a bit complicated; it needs to be done in a few steps per keybinding. On the other hand, it is pretty straightforward and can very well be scripted if you somehow want to do it from the command line (that was the question, right?).
Just like in your interface (System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts"), Custom keyboard shortcuts are made from command line in two steps:
create the keybinding by editing (adding to-) the list that is returned by the command:
The returned list looks like (if it were only one shortcut currently):
Apply the edited list by the command:
(mind the double quotes)
N.B. No need to say that the mention in the list (e.g.
custom1
,custom2
) should be a unique one. If you script it, the script should prevent duplicates. In this case the edited list should look like e.g.:to add one keybinding:
custom1
set its properties:
name:
command:
Key combination (for example
<Primary><Alt>g
):Useful information can be found here
Example script to set a new custom shortcut
The script below can be used to set a new shortcut key combination from the command line. It can be used with the command (assuming the key combination is available):
An example:
To set a shortcut key combination to open
gedit
with the key combination Alt+7:The script:
How to use:
Paste the script into an empty file, save it as
set_customshortcut.py
, run it as explained above.Some of the mostly used key mentions (found experimentally, looking into the changes the GUI way made into the binding value):
etc.