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.

#!/bin/bash

BEGINNING="gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings"

KEY_PATH="/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings"

gsettings set org.gnome.settings-daemon.plugins.media-keys 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"

For self-use, here is the one-line command to execute the script:

curl -s https://scripts.programster.org/scripts/4?output=raw | bash

Author

Programster

Stuart is a software developer with a passion for Linux and open source projects.

comments powered by Disqus
We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to Amazon.com and affiliated sites. More info.