Skip to content

Instantly share code, notes, and snippets.

@kwon37xi
Last active August 15, 2020 22:40
Show Gist options
  • Save kwon37xi/68a7ea43759ba270e9ae224d314b959a to your computer and use it in GitHub Desktop.
Save kwon37xi/68a7ea43759ba270e9ae224d314b959a to your computer and use it in GitHub Desktop.
#!/bin/bash
# Gnome 3 based workspace changer
# only works with gnome 3 vertical workspace
# workspace-switcher.sh Up
# workspace-switcher.sh Down
#
# ref : https://www.artificialworlds.net/blog/2011/03/04/switching-workspace-in-gnome-via-the-command-line/
CMD="$1"
NUM_WORKSPACES=`gsettings get org.gnome.desktop.wm.preferences num-workspaces`
CURRENT_WS=`wmctrl -d | grep \* | cut -d " " -f 1`
MOVE_UP="-1"
MOVE_DOWN="+1"
case $CMD in
"Up" )
WS_COL=`echo $CURRENT_WS "%" $NUM_WORKSPACES | bc`
if [[ $WS_COL -eq 0 ]]; then
{
NEW_WS=$CURRENT_WS
}
else
{
NEW_WS=`echo $CURRENT_WS "- 1" | bc`
}; fi
;;
"Down" )
NEW_WS=`echo $CURRENT_WS "+ 1" | bc`
NEW_WS_COL=`echo $NEW_WS "%" $NUM_WORKSPACES | bc`
if [[ $NEW_WS_COL -eq 0 ]]; then NEW_WS=$CURRENT_WS; fi
;;
* )
NEW_WS=$CMD
esac
wmctrl -s $NEW_WS
@kwon37xi
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment