45 lines
1.1 KiB
Bash
45 lines
1.1 KiB
Bash
|
#!/bin/bash
|
||
|
|
||
|
# name: switch_desktop.sh
|
||
|
# version: 0.1
|
||
|
# author: david@socialnerds.org
|
||
|
# description: switch to next, previous, specific desktop.
|
||
|
# you can also toggle between first and second desktop.
|
||
|
#
|
||
|
# usage: ./switch-desktop.sh next|prev|<int>|toggle
|
||
|
|
||
|
num=$(wmctrl -d | grep "*" | awk '{print $1}')
|
||
|
lockfile="/tmp/switch_desktop.lock"
|
||
|
|
||
|
if [ ! -f $lockfile ]; then
|
||
|
echo "creating lockfile [$lockfile]"
|
||
|
touch $lockfile
|
||
|
|
||
|
if [[ "$1" =~ ^[0-9]+$ ]]; then
|
||
|
echo "switching to specific desktop [$1]"
|
||
|
wmctrl -s $1
|
||
|
elif [ "$1" == "next" ]; then
|
||
|
echo "switching to next desktop [$next]"
|
||
|
next=$((num+1))
|
||
|
wmctrl -s $next
|
||
|
elif [ "$1" == "prev" ]; then
|
||
|
if [ $num -ne 0 ]; then
|
||
|
echo "switching to previous desktop [$prev]"
|
||
|
prev=$((num-1))
|
||
|
wmctrl -s $prev
|
||
|
fi
|
||
|
elif [ "$1" == "toggle" ]; then
|
||
|
if [ $num -eq 0 ]; then
|
||
|
echo "switching to second desktop"
|
||
|
wmctrl -s 1
|
||
|
else
|
||
|
echo "switching back to first desktop"
|
||
|
wmctrl -s 0
|
||
|
fi
|
||
|
fi
|
||
|
echo "waiting for 0.5 seconds"
|
||
|
sleep 0.5
|
||
|
echo "cleaning up lockfile [$lockfile]"
|
||
|
rm $lockfile
|
||
|
fi
|