Last active
April 8, 2019 08:13
-
-
Save belltailjp/92201f3990492acd8eb5d14b65b84dbb to your computer and use it in GitHub Desktop.
Toggle Zeal window active
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 | |
# Launch zeal, and bring it to top screen | |
# If it is already on top, bring it to the back (toggle) | |
DEBUG=0 | |
if [ ! -e /usr/bin/zeal ]; then | |
if [ $DEBUG ]; then | |
echo "Zeal not found in /usr/bin/zeal" | |
fi | |
exit | |
fi | |
CURRENT_ACTIVE_WINDOW_ID=`xdotool getactivewindow` | |
ZEAL_WINDOW_ID=`xdotool search --name " - Zeal" | head -n 1` | |
if [ $DEBUG ]; then | |
echo "Current active window is $CURRENT_ACTIVE_WINDOW_ID ('`xdotool getwindowname $CURRENT_ACTIVE_WINDOW_ID`')" | |
echo "Zeal window is $ZEAL_WINDOW_ID ('`xdotool getwindowname $ZEAL_WINDOW_ID`')" | |
fi | |
if [ $CURRENT_ACTIVE_WINDOW_ID -eq $ZEAL_WINDOW_ID ]; then | |
if [ $DEBUG ]; then | |
echo "Zeal is already top window" | |
fi | |
# Zeal is already running and top-screen -> Bring it to behind | |
if [ -e /tmp/.last_active_window ]; then | |
LAST_ACTIVE_WINDOW_ID=`cat /tmp/.last_active_window` | |
xdotool windowactivate $LAST_ACTIVE_WINDOW_ID | |
if [ $DEBUG ]; then | |
echo Bring "`xdotool getwindowname $LAST_ACTIVE_WINDOW_ID`" to the front | |
fi | |
else | |
if [ $DEBUG ]; then | |
echo "/tmp/.last_active_window cannot be found." | |
fi | |
fi | |
else | |
if [ $DEBUG ]; then | |
echo "Zeal is neither activated nor launched" | |
fi | |
# Memorize current active window | |
echo $CURRENT_ACTIVE_WINDOW_ID > /tmp/.last_active_window | |
# Launch zeal and bring it to the front | |
/usr/bin/zeal | |
xdotool search --name " - Zeal" windowactivate | |
fi | |
# c.f. | |
# https://ubuntuincident.wordpress.com/2013/01/10/find-window-by-its-name-and-activate-it-bring-to-foreground/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment