-
Notifications
You must be signed in to change notification settings - Fork 0
/
chinese_bluetooth_lady.sh
45 lines (36 loc) · 1.3 KB
/
chinese_bluetooth_lady.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
CONNECTED_SOUND="./chinese_bluetooth_lady_connect.mp3"
DISCONNECTED_SOUND="./chinese_bluetooth_lady_disconnect.mp3"
# Function that lists the currently connected devices
check_devices () {
bluetoothctl paired-devices | cut -f2 -d' '|
while read -r uuid
do
info=`bluetoothctl info $uuid`
if echo "$info" | grep -q "Connected: yes"; then
echo "$info" | grep "Name"
fi
done
}
# Store the initial list of paired devices
initial_devices=$(check_devices)
# Play the disconnected audio at initial boot
#play "$DISCONNECTED_SOUND"
while true; do
# Get the current list of paired devices
current_devices=$(check_devices)
# Check for newly connected devices
newly_connected=$(comm -13 <(echo "$initial_devices") <(echo "$current_devices"))
# Check for newly disconnected devices
newly_disconnected=$(comm -13 <(echo "$current_devices") <(echo "$initial_devices"))
if [[ -n $newly_connected ]]; then
# A device is newly connected
play "$CONNECTED_SOUND"
initial_devices="$current_devices" # Update initial list
elif [[ -n $newly_disconnected ]]; then
# A device is newly disconnected
play "$DISCONNECTED_SOUND"
initial_devices="$current_devices" # Update initial list
fi
sleep 3 # Adjust the interval as needed
done