Script to launch Plank items using WIN+number hotkey
Posted on 16 April 2016 in linux
Dependences
dconf-tools
wmctrl
Description
What does this script is reading current order of items using dconf
then it looks at plank config directory for an appropriate launcher, finds the .desktop file and see what command is supposed to be executed.
In order not to launch multiple instances of an item it checks if a window is opened and shows it instead.
If it doesn't work for you, you will need to check what windows name is used for your applications using
wmcrl -x -l
For Thunar it's Thunar, for instance. For example a Google Chrome window is called "google-chrome" but a command is google-chrome-stable
though.
Code
#!/bin/bash
dock="dock1"
read -a arr <<< $(dconf read /net/launchpad/plank/docks/$dock/dock-items|sed -e "s/\(\[\|\]\)//g" -e "s/ /\\\\\ /g" -e "s/',\\\ '/ /g" -e "s/'//g")
#read -a arr <<<`cat ~/.config/plank/$dock/settings|grep DockItems|sed -e 's/^DockItems=//' -e "s/ /\\\\\ /g" -e "s/;;/ /g"`
app=$(cat "`cat .config/plank/$dock/launchers/"${arr[(($1-1))]}"|grep Launcher|sed -e "s/Launcher=file:\/\///" -e 's/%20/ /g'`"|grep "Exec"|head -1|sed -e "s/^[^=]*=//g" -e "s/%.//g")
if grep -q google-chrome-stable <<< $app;then
wmctrl -x -a google-chrome || $app
else
wmctrl -x -a $app || $app
fi
Settings
Set this script in your DE keyboard settings for WIN+1 as launchPlank.sh 1
for WIN+2 as launchPlank.sh 2
etc.
Have fun!