Skip to content

Instantly share code, notes, and snippets.

@nikallass
Last active October 21, 2019 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikallass/18d6129ab6220fe07f20c3fd9ba9019b to your computer and use it in GitHub Desktop.
Save nikallass/18d6129ab6220fe07f20c3fd9ba9019b to your computer and use it in GitHub Desktop.
Toggle terminator. Kali
#!/bin/bash
# hotkey for prefrences /root/toggle_terminator.sh terminator
# on first start run script manually to install dependencies
#
# This script does this:
# launch an app if it isn't launched yet,
# focus the app if it is launched but not focused,
# minimize the app if it is focused.
#
# by desgua - 2012/04/29
# modified by olds22 - 2012/09/16
# - customized to accept a parameter
# - made special exception to get it working with terminator
# First let's check if the needed tools are installed:
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 we're trying to use an app that needs a special process name
# (because it runs multiple processes and/or under a different name)
app=$1
if [[ $app == terminator ]]; then
process_name=usr/bin/terminator
else
process_name=$app
fi
# Check if the app is running (in this case $process_name)
#pid=$(pidof $process_name) # pidof didn't work for terminator
pid=$(pgrep -f $process_name)
# If it isn't launched, then launch
if [ -z "$pid" ]; then
$app --borderless --fullscreen
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 $app
fi
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment