Created
March 10, 2013 00:54
-
-
Save bltavares/5126585 to your computer and use it in GitHub Desktop.
Toggle window or open the program
This file contains hidden or 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/bash | |
tool1=$(which xdotool) | |
tool2=$(which wmctrl) | |
if [ -z $tool1 ]; then | |
echo "Xdotool is needed, do you want to install it now? [Y/n]" | |
read a | |
if [[ $a == "Y" || $a == "y" || $a = "" ]]; then | |
sudo apt-get install xdotool | |
else | |
echo "Exiting then..." | |
exit 1 | |
fi | |
fi | |
if [ -z $tool2 ]; then | |
echo "Wmctrl is needed, do you want to install it now? [Y/n]" | |
read a | |
if [[ $a == "Y" || $a == "y" || $a = "" ]]; then | |
sudo apt-get install wmctrl | |
else | |
echo "Exiting then..." | |
exit 1 | |
fi | |
fi | |
# Check if the app is running (in this case stardict) | |
pid=$(pidof $1) | |
# If it isn't launched, then launch | |
if [ -z $pid ]; then | |
$@ & | |
else | |
# If it is launched then check if it is focused | |
foc=$(xdotool getactivewindow getwindowpid) | |
if [[ $pid == $foc ]]; then | |
# if it is focused, then minimize | |
xdotool getactivewindow windowminimize | |
else | |
# if it isn't focused then get focus | |
wmctrl -x -R $1 | |
fi | |
fi | |
exit 0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment