desks.sh (raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
#!/bin/sh # this is a simple script to both give some semblance of eye-candy for a tint2 executor # and to switch virtual desktops programmatically, to be invoked by button click/scroll # on said executor. # Derek Stevens <nilix@nilfm.cc> # MIT License # if we're feeling spartan, just print a simple string for the executor if [ -z $1 ]; then echo "" # if we pass '-x', spit a few hexadecimal bytes into the executor for eye-candy elif [ "$1" = "-x" ]; then od -vAn -N2 -x < /dev/urandom # otherwise switch desks else currentDeskNum=$(wmctrl -d | grep -n [*] | awk '{print $1}' | awk -F : '{print $1}') numDesks=$(wmctrl -d | wc -l) case $1 in "-n") if [ ${currentDeskNum} -eq ${numDesks} ]; then newDesk=$(wmctrl -d | head -n 1 | awk '{print $1}') else newDesk=$(wmctrl -d | head -n $((currentDeskNum + 1)) | tail -n 1 | awk '{print $1}') fi ;; "-p") if [ ${currentDeskNum} -eq 1 ]; then newDesk=$(wmctrl -d | tail -n 1 | awk '{print $1}') else newDesk=$(wmctrl -d | head -n $((currentDeskNum - 1)) | tail -n 1 | awk '{print $1}') fi ;; esac wmctrl -s ${newDesk} fi |