Skip to content

Instantly share code, notes, and snippets.

@bltavares
Created March 10, 2013 00:54
Show Gist options
  • Save bltavares/5126585 to your computer and use it in GitHub Desktop.
Save bltavares/5126585 to your computer and use it in GitHub Desktop.
Toggle window or open the program
#!/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