-
Notifications
You must be signed in to change notification settings - Fork 2
/
zoomwatcher
executable file
·109 lines (96 loc) · 3.17 KB
/
zoomwatcher
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
# A service that watches for zoom and turns a hue light red if it is running.
usage() {
echo "usage: ${0##*/} [options]" 1>&2
echo "" 1>&2
echo "A service that watches for zoom and turns a hue light red if it is running." 1>&2
echo ""
echo "options:"
echo " -h or --help shows usage help" 1>&2
exit 1
}
if echo "$*" | grep -Eq -- '--help\b|-h\b'; then
usage
fi
# shellcheck source=.hue_control
# shellcheck disable=SC1091
source "$HOME/.hue_control" || echo "$(tput bold)error: ~/.hue_control not installed!$(tput sgr0)" >&2
ERRF="/tmp/zoomwatcher.err"
BR_TABS=""
brave_tabs() {
BRAVE="osascript -e 'tell application \"System Events\" to (name of processes) contains \"Brave Browser\"'"
if test "$(eval "$BRAVE")" = "true"; then
osascript <<EOF
set titleString to ""
tell application "Brave Browser"
set window_list to every window # get the windows
repeat with the_window in window_list # for every window
set tab_list to every tab in the_window # get the tabs
repeat with the_tab in tab_list # for every tab
set the_url to the URL of the_tab # grab the URL
set titleString to titleString & the_url & "\n"
end repeat
end repeat
end tell
EOF
fi
}
CH_TABS=""
chrome_tabs() {
CHROME="osascript -e 'tell application \"System Events\" to (name of processes) contains \"Google Chrome\"'"
if test "$(eval "$CHROME")" = "true"; then
osascript <<EOF
set titleString to ""
tell application "Google Chrome"
set window_list to every window # get the windows
repeat with the_window in window_list # for every window
set tab_list to every tab in the_window # get the tabs
repeat with the_tab in tab_list # for every tab
set the_url to the URL of the_tab # grab the URL
set titleString to titleString & the_url & "\n"
end repeat
end repeat
end tell
EOF
fi
}
ZOOM="false"
zoom_running() {
osascript -e 'tell application "System Events" to (name of processes) contains "zoom.us"'
}
in_meeting() {
test "$ZOOM" = "true" ||
echo "$BR_TABS" | /usr/bin/grep -q "meet.google.com" ||
echo "$CH_TABS" | /usr/bin/grep -q "meet.google.com"
}
in_game() {
ps -efw | grep "Steam" | grep -Eiv "helper|ipcserver|grep" ||
echo "$BR_TABS" | /usr/bin/grep -q "spelltable" ||
echo "$CH_TABS" | /usr/bin/grep -q "spelltable"
}
while true; do
ZOOM="$(eval "$ZOOM")"
BR_TABS="$(eval brave_tabs)"
CH_TABS="$(eval chrome_tabs)"
ZOOM="$(eval zoom_running)"
if ! hue_is_busy; then
NOW="$(date)"
if in_meeting; then
if ! hue_is_red; then
echo "$NOW: setting color set to red..." >>"$ERRF"
hue_set_color red >>"$ERRF"
fi
elif in_game; then
if ! hue_is_purple; then
echo "$NOW: setting color set to purple..." >>"$ERRF"
hue_set_color purple >>"$ERRF"
fi
else
if ! hue_is_green; then
echo "$NOW: setting color set to green..." >>"$ERRF"
hue_set_color green >>"$ERRF"
fi
fi
fi
sleep 1
done