Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Using the CLI to Set Custom Keyboard Shortcuts

Manually configuring your keyboard shortcuts through the GUI is easy enough, but its tedious for those who have a lot of shortcuts and change computers frequently. As with all things Linux, there is a way to do it through the CLI, and thus can be executed as a script. Below is my bash script that sets my keyboard shortcuts up for me. It should be easy enough for you to tweak it for your needs.


BEGINNING="gsettings set"


gsettings set custom-keybindings \
"['$KEY_PATH/custom0/', '$KEY_PATH/custom1/', '$KEY_PATH/custom2/', '$KEY_PATH/custom3/', '$KEY_PATH/custom4/', '$KEY_PATH/custom5/']"

# Take a screenshot of the entire display
$BEGINNING/custom0/ name "Take Full Screenshot"
$BEGINNING/custom0/ command "shutter --full"
$BEGINNING/custom0/ binding "Print"

# screenshot the current active window
$BEGINNING/custom1/ name "Grab Active Window"
$BEGINNING/custom1/ command "shutter --active"
$BEGINNING/custom1/ binding "<Alt>Print"

# Take a selection of screen with screenshot
$BEGINNING/custom2/ name "Screenshot Selection"
$BEGINNING/custom2/ command "shutter --select"
$BEGINNING/custom2/ binding "<Shift>Print"

# Launch Terminal
$BEGINNING/custom3/ name "Gnome Terminal"
$BEGINNING/custom3/ command "gnome-terminal"
$BEGINNING/custom3/ binding "<Super>Q"

# Open up file browser
$BEGINNING/custom4/ name "Nautilus"
$BEGINNING/custom4/ command "/usr/bin/nautilus --new-window"
$BEGINNING/custom4/ binding "<Super>E"

# Launch Synapse (Launchy Equivalent)
$BEGINNING/custom5/ name "Synapse"
$BEGINNING/custom5/ command "/usr/bin/synapse"
$BEGINNING/custom5/ binding "<Super>R"
Last updated: 17th April 2021
First published: 16th August 2018