Advertisement
Guest User

findapp.sh

a guest
Nov 18th, 2016
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.84 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # This script searchs for the application with the
  4. # given classname. There are three possibilities:
  5. #     1. If the app is not open, opens it
  6. #     2. If the app is open but is not the active window, activates it
  7. #     3. If the app is open AND is the active window, minimizes it#
  8. # The idea is to assign this script to keyboard shortcuts in order
  9. # to launch/activate/minimize a common used application quickly
  10. #
  11. # Requieres 'xdotool' installed
  12.  
  13. APPNAME="$1"
  14. WINDOWIDS=( $(xdotool search --class $APPNAME) )
  15. ACTIVEWINDOW=$(xdotool getactivewindow)
  16.  
  17. if [ -n "$WINDOWIDS" ]; then
  18.     for i in "${WINDOWIDS[@]}"
  19.     do
  20.         # si es la ventana activa la miniza, si no, la activa
  21.         if [ "$i" == "$ACTIVEWINDOW" ]; then
  22.             xdotool windowminimize $i &
  23.         else
  24.             xdotool windowactivate $i &
  25.         fi
  26.     done
  27. else
  28.     $APPNAME "${@:2}" &
  29. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement