forked from HedgeInSmog/wacom-profile-switcher
-
Notifications
You must be signed in to change notification settings - Fork 1
/
wacom-profile-switcher.sh
executable file
·45 lines (42 loc) · 1.38 KB
/
wacom-profile-switcher.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
awk_string1="/"
awk_string2="/{print \$1}"
window_in_focus_old=""
INSTALLDIR=$HOME/git/wacom-profile-switcher
while true
do
#get ID of windows in the focus
window_in_focus=`xprop -root |awk '/_NET_ACTIVE_WINDOW/ {print $5; exit;}'`
#if the focus didn't change - do nothing
if [[ "$window_in_focus" -ne "$window_in_focus_old" ]]
then
window_in_focus_old=$window_in_focus
#reading program's name from file "programs"
list_of_progr=$(<$INSTALLDIR/programs)
# program's names cycle
IFS=$'\n'
found=0
for name_of_progr in $list_of_progr
do
awk_string_result="$awk_string1$name_of_progr$awk_string2"
# getting the list of windows, wich titles has keyword from list of programs
list_of_running_prog=`wmctrl -l | awk "${awk_string_result}"`
# if in focus - then will execute script in the xsetwacom directory
for running_progr in $list_of_running_prog
do
if [[ "$running_progr" -eq "$window_in_focus" ]]
then
$INSTALLDIR/"$name_of_progr"
found=1
default=0
fi
done
done
if [ "$found" = "0" ] && [ "$default" = "0" ]
then
$INSTALLDIR/Default
default=1
fi
fi
sleep 1
done