Created
August 10, 2012 08:13
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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