Created
February 5, 2018 20:37
-
-
Save MisterPixels/169ff484cd0d3bf2821f5dc91c3f060c to your computer and use it in GitHub Desktop.
Automatic assignment of Superkey+1/9 to shortcuts on the lxde panel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
##PLEASE BACKUP YOUR OPENBOX XML FILE BEFORE USING THIS SCRIPT. | |
##THIS IS A SAFETY MEASURE IN THE EVENT THAT THE SCRIPT FAILS TO EXECUTE CORRECTLY! | |
##This script reads the desktop shortcuts from the panel file and adds up to 9 shortcuts to the openbox xml file. | |
##Allowing you to use super+1/9 to open applications from your panel using the keyboard | |
##Instructions: To apply shortcuts: "./supershortcuts.sh /path/to/panel/file /path/to/openbox/config/xml/file | |
##To get rid of the shortcuts again simply type: "./supershortcuts.sh remove /path/to/openbox/config/xml/file | |
if [ $1 == 'remove' ]; ##if argument 1 is remove then execute the sed command to remove all the shortcuts | |
then | |
sed -i '/<!--SUPERSHORTCUTS-->/,/<!--ENDOFSUPERSHORTCUTS-->/d' $2 | |
else ##else execute the following | |
PANELFILE=$1 ##assigning the filepath to PANELFILE for ease of use during writing of script | |
OPENBOXCONFIG=$2 ##assigning the filepath to OPENBOXCONFIG for ease of use during writing of script | |
PANELFILECOUNT=$(cat $PANELFILE | grep -c .desktop) ##to store the amount of shortcuts needed in case there are less than 9 causing the script to fail otherwise | |
if (( $PANELFILECOUNT <= 0 )); ##if there are no .desktop shortcuts to be found it means that the wrong panel file is chosen and nothing will change | |
then | |
echo "Can't find anything to shortcut. Please make sure you have selected the right file" | |
else | |
sed -i '/<!--SUPERSHORTCUTS-->/,/<!--ENDOFSUPERSHORTCUTS-->/d' $OPENBOXCONFIG ##remove previous shortcuts added by script to prevent double assignments | |
sed -i "/<\/keyboard>/i <!--SUPERSHORTCUTS-->" $OPENBOXCONFIG ##add the line <!--SUPERSHORTCUTS--> at the begining of the newly added shortcuts | |
counter=1 ##counter needed for the while loop. | |
while (($counter <= 9 && $counter <= $PANELFILECOUNT)) ##while the counter is lower or equal than 9 and the PANELFILECOUNT keep running the loop to add shortcuts | |
do | |
input=$(cat $PANELFILE | grep .desktop | sed 's/id=//g' | sed 's/ //g' | sed $counter'q;d') ##grabs the .desktop shortcut depending on which number the counter is | |
sed -i "/<\/keyboard>/i <keybind key='W-$counter'>\n <action name='Execute'>\n <command>xdg-open \/usr\/share\/applications\/$input<\/command>\n <\/action>\n<\/keybind>" $OPENBOXCONFIG ## adds the information to the openbox config xml file | |
((++counter)) ##increase counter by 1 | |
done | |
sed -i "/<\/keyboard>/i <!--ENDOFSUPERSHORTCUTS-->" $OPENBOXCONFIG ##add the line <!--ENDOFSUPERSHORTCUTS--> at the end of the newly added shortcuts | |
fi | |
fi | |
openbox --restart ##restart openbox to apply the removal or adding of shortcuts so they can be used right away |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment