Skip to content

Instantly share code, notes, and snippets.

@tomasklapka
Created August 10, 2012 08:13
Show Gist options
  • Save tomasklapka/3312541 to your computer and use it in GitHub Desktop.
Save tomasklapka/3312541 to your computer and use it in GitHub Desktop.
Focuses X application or runs it if not running (requires wmctrl utility installed)
#!/bin/sh
terminal_wm_class=$1
terminal_exec=$1
# no app started, so start one
if [ -z "`wmctrl -lx | grep $1`" ]; then
$terminal_exec &
else
# search for existing terminals on current desktop
current_desk=`wmctrl -d | grep '*' | cut -d ' ' -f 1`
term_on_this_desk=`wmctrl -lx | grep "$current_desk[ ]*$terminal_wm_class" | cut -d ' ' -f 1`
if [ -n "$term_on_this_desk" ]; then
wmctrl -i -a $term_on_this_desk
else
# no terminals on current desktop, so just open a new one
wmctrl -x -R $terminal_wm_class
fi;
fi;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment