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.

#!/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"
Last updated: 17th April 2021
First published: 16th August 2018

This blog is created by Stuart Page

I'm a freelance web developer and technology consultant based in Surrey, UK, with over 10 years experience in web development, DevOps, Linux Administration, and IT solutions.

Need support with your infrastructure or web services?

Get in touch