Skip to content

Instantly share code, notes, and snippets.

@aauren
Last active August 29, 2015 14:14
Show Gist options
  • Save aauren/c8a5513ba1cc5d734994 to your computer and use it in GitHub Desktop.
Save aauren/c8a5513ba1cc5d734994 to your computer and use it in GitHub Desktop.
Linux Desktop Window Switching
#!/usr/bin/env bash
# Creates a dialog using Zenity that lists all of your open windows and then switches to whatever window matches your input
# Requires Zenity, wmctrl, and xdotool packages
WINDOW_TITLES=$(wmctrl -l | grep -v "\-1" | sed -r 's/([^ ]+ +){3}(.*)/\2/g')
WINDOW_SELECTION=$(zenity --entry --title="Choose a Window" --text="${WINDOW_TITLES}")
DESKTOP_NUMBER=$(wmctrl -l | grep -v "\-1" |grep -m 1 ${WINDOW_SELECTION} | sed -r 's/^[^ ]+ +([^ ]+) .*/\1/g')
echo "Selection: ${WINDOW_SELECTION} Desktop: ${DESKTOP_NUMBER}"
xdotool search --desktop ${DESKTOP_NUMBER} --name ${WINDOW_SELECTION} windowactivate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment