smartlaunch.sh (1561B)
1 #!/bin/bash 2 3 # To use the script, bind it to a key combination in dwm's config.h, and also bind THE SAME KEY to switch to the dedicated tag for the window to be launched. 4 5 # Import pre-emptive values 6 CLASSONLY=0 7 8 # Opts 9 while [[ "$#" -gt 0 ]]; do 10 case $1 in 11 -C|--classonly) 12 CLASSONLY=1; shift ;; 13 esac 14 shift 15 done 16 17 if [ $CLASSONLY -eq 0 ]; then 18 CMDNAME=$1 # The command to execute if no matching window is found. 19 PROPNAME=$2 # A string that should match 'WM_NAME' for the target window, in whole or in part. See xprop(1). 20 PROPCLASS=$3 # A string that should match *THE FIRST FIELD* of 'WM_CLASS' in the target window, in whole or in part. See xprop(1) 21 else 22 CMDNAME=$1 # The command to execute if no matching window is found. 23 PROPCLASS=$2 # A string that should match *THE FIRST FIELD* of 'WM_CLASS' in the target window, in whole or in part. See xprop(1) 24 fi 25 26 WINIDS=$(xwininfo -root -tree | grep -o '^[[:space:]]*0x.\{7\}') 27 EXISTS=0 28 29 # Opts 30 while [[ "$#" -gt 0 ]]; do 31 case $1 in 32 -C|--classonly) 33 CLASSONLY=1; shift ;; 34 esac 35 shift 36 done 37 38 for w in $WINIDS; do 39 props=$(xprop -id $w | grep '^WM_NAME\|^WM_CLASS') 40 if [ $CLASSONLY -eq 0 ]; then 41 if [[ $props == *"WM_NAME("*") = \"$PROPNAME"* && $props == *"WM_CLASS("*") = \"$PROPCLASS"* ]]; then 42 EXISTS=1 43 fi 44 else if [[ $props == *"WM_CLASS("*") = \"$PROPCLASS"* ]]; then 45 EXISTS=1 46 fi 47 fi 48 done 49 if [ $EXISTS -eq 0 ]; then 50 exec $CMDNAME 51 fi 52 unset w props