-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoggle-speakers.sh
executable file
·40 lines (34 loc) · 1.06 KB
/
toggle-speakers.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
#!/usr/bin/env bash
# variables --------------------------------------------------------------------
device_name="google-home"
# functions --------------------------------------------------------------------
function get_device_mac () {
device_mac="$1"
bluetoothctl devices |
awk '$3 == "'"$device_mac"'" { print $2 }'
}
function is_device_blocked () {
device_mac="$1"
bluetoothctl info "$device_mac" |
awk '$1 == "Blocked:" { print $2 }'
}
function toggle_action () {
device_blocked="$1"
[ "$device_blocked" == "yes" ] &&
action="unblock" ||
action="block"
echo "$action"
}
# setup ------------------------------------------------------------------------
device_mac=$(get_device_mac "$device_name")
device_blocked=$(is_device_blocked "$device_mac")
# execution ====================================================================
case $device_blocked in
no)
bluetoothctl block "$device_mac"
;;
yes)
bluetoothctl unblock "$device_mac"
bluetoothctl connect "$device_mac"
;;
esac