Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # This script does this:
  4. # launch an app if it isn't launched yet,
  5. # focus the app if it is launched but not focused,
  6. # minimize the app if it is focused.
  7. #
  8. # by desgua - 2012/04/29
  9. # modified by olds22 - 2012/09/16
  10. # - customized to accept a parameter
  11. # - made special exception to get it working with terminator
  12.  
  13.  
  14. # First let's check if the needed tools are installed:
  15.  
  16. tool1=$(which xdotool)
  17. tool2=$(which wmctrl)
  18.  
  19. if [ -z $tool1 ]; then
  20. echo "Xdotool is needed, do you want to install it now? [Y/n]"
  21. read a
  22. if [[ $a == "Y" || $a == "y" || $a = "" ]]; then
  23. sudo apt-get install xdotool
  24. else
  25. echo "Exiting then..."
  26. exit 1
  27. fi
  28. fi
  29.  
  30. if [ -z $tool2 ]; then
  31. echo "Wmctrl is needed, do you want to install it now? [Y/n]"
  32. read a
  33. if [[ $a == "Y" || $a == "y" || $a = "" ]]; then
  34. sudo apt-get install wmctrl
  35. else
  36. echo "Exiting then..."
  37. exit 1
  38. fi
  39. fi
  40.  
  41.  
  42. # check if we're trying to use an app that needs a special process name
  43. # (because it runs multiple processes and/or under a different name)
  44. app=$1
  45. if [[ $app == terminator ]]; then
  46. process_name=usr/bin/terminator
  47. else
  48. process_name=$app
  49. fi
  50.  
  51. # Check if the app is running (in this case $process_name)
  52. #pid=$(pidof $process_name) # pidof didn't work for terminator
  53. pid=$(pgrep -f $process_name)
  54.  
  55. # If it isn't launched, then launch
  56.  
  57. if [ -z $pid ]; then
  58. $app
  59.  
  60. else
  61. # If it is launched then check if it is focused
  62.  
  63. foc=$(xdotool getactivewindow getwindowpid)
  64. if [[ $pid == $foc ]]; then
  65.  
  66. # if it is focused, then minimize
  67. xdotool getactivewindow windowminimize
  68. else
  69. # if it isn't focused then get focus
  70. wmctrl -x -R $app
  71. fi
  72. fi
  73.  
  74. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement