Skip to content

Instantly share code, notes, and snippets.

@truetamtam
Last active October 7, 2015 13:03
Show Gist options
  • Select an option

  • Save truetamtam/38b33dda3a09a5d04bdc to your computer and use it in GitHub Desktop.

Select an option

Save truetamtam/38b33dda3a09a5d04bdc to your computer and use it in GitHub Desktop.
Switch to last window of the application. Search by name in title. Uses wmctrl & xprop. Origin: http://askubuntu.com/a/562191
#!/bin/bash
# Origin: http://askubuntu.com/a/562191
# required: wmctrl
app=$1
workspace=$(wmctrl -d | grep '\*' | cut -d ' ' -f1)
win_list=$(wmctrl -lx | grep $app | grep " $workspace " | awk '{print $1}')
IDs=$(xprop -root|grep "^_NET_CLIENT_LIST_STACKING" | tr "," " ")
IDs=(${IDs##*#})
for (( idx=${#IDs[@]}-1 ; idx>=0 ; idx-- )) ; do
for i in $win_list; do
if [ $((i)) = $((IDs[idx])) ]; then
wmctrl -ia $i
exit 0
fi
done
done
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment