-
Notifications
You must be signed in to change notification settings - Fork 1
/
btchanged.sh
executable file
·81 lines (61 loc) · 1.34 KB
/
btchanged.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
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
#!/bin/sh
#
# Notify changes in bluetooth connected devices
#
# TODO support multiple exclude devices
#
EXCLUDE="eahmbp\|eahxs\|Ernie.s.MacBook"
if [ -e ~/.bashrc ]
then
. ~/.bashrc
fi
if ! which -s terminal-notifier
then
echo "Missing terminal-notifier executable in path" >&2
echo "To fix, run:" >&2
echo " brew install terminal-notifier" >&2
exit 2
fi
last_list=/tmp/btold
now_list=/tmp/btnow
log=/tmp/btlog
lsbt=~ernie/git/utilities/lsbt
tempfile="$(mktemp)"
date >> "$log"
if [ ! -e "$last_list" ]
then
$lsbt -c > "$last_list"
fi
$lsbt -c > "$now_list"
TEST=""
#TEST=1
if [ "$TEST" ]
then
echo 'ODT Privates BLUE' > $now_list
fi
diff "$last_list" "$now_list" >> "$log"
diff "$last_list" "$now_list" > "$tempfile"
if [ "$EXCLUDE" ]
then
exclude_command="grep -vE $EXCLUDE"
else
exclude_command="cat"
fi
grep ^\< "$tempfile" | sed 's/^< //' | LANG=en_us eval $exclude_command | while read device
do
terminal-notifier -title DISCONNECTED -message "$device"
echo "DISCONNECTED - $device" >> "$log"
echo "set:" >> "$log"
set >> "$log"
done
grep ^\> "$tempfile" | sed 's/^> //' | LANG=en_us eval $exclude_command | while read device
do
terminal-notifier -title CONNECTED -message "$device"
echo "CONNECTED - $device" >> "$log"
echo "env:" >> "$log"
env >> "$log"
done
if [ ! "$TEST" ]
then
cp "$now_list" "$last_list"
fi