Skip to content

Instantly share code, notes, and snippets.

@Caerostris
Created August 26, 2014 07:11
Show Gist options
  • Save Caerostris/83fcda921ebf8e3df9fd to your computer and use it in GitHub Desktop.
Save Caerostris/83fcda921ebf8e3df9fd to your computer and use it in GitHub Desktop.
This is a bash script for Ubuntu which registers a keyboard shortcut.
#!/bin/bash
if [ "$#" -ne 3 ]; then
echo "Usage: $0 name command binding"
echo "Example: $0 \"screenshot\" \"gnome-screenshot\" \"<Primary><Alt>s\""
exit
fi
GSETTINGS_PATH="org.gnome.settings-daemon.plugins.media-keys"
KEY_PATH="/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings"
GSETTINGS="gsettings set $GSETTINGS_PATH.custom-keybinding:$KEY_PATH"
i=0
while [ "$(gsettings get $GSETTINGS_PATH.custom-keybinding:$KEY_PATH/custom$i/ name)" != "''" ]
do
i=$(( $i + 1 ))
done
CK=$(gsettings get $GSETTINGS_PATH custom-keybindings)
if [ "$CK" == "@as []" ]; then
gsettings set $GSETTINGS_PATH custom-keybindings "['$KEY_PATH/custom0/']"
else
gsettings set $GSETTINGS_PATH custom-keybindings "${CK%]}, '$KEY_PATH/custom$i/']"
fi
$GSETTINGS/custom$i/ name "$1"
$GSETTINGS/custom$i/ command "$2"
$GSETTINGS/custom$i/ binding "$3"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment