-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathheadphones
executable file
·48 lines (41 loc) · 1.2 KB
/
headphones
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
#!/bin/sh
# headphones: connect/disconnect/setprofile to bluetooth headphones.
set -e
die() {
echo "error:" "$@" >&2
exit 1
}
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "usage: headphones device [on|off|a2dp|hfp]"
exit 0
elif [ -z "$1" ]; then
die "device not provided"
elif ! echo "$1" | grep -q ':'; then
die "$1: invalid device (should be a mac address)"
fi
device="$1"
bluezcard="bluez_card.$(echo "$device" | tr ':' '_')"
defaultprofile="a2dp_sink"
op="$2"
case "$op" in
"off")
bluetoothctl disconnect "$device"
;;
"" | "on")
bluetoothctl connect "$device"
sleep 2 # give pulse audio time to detect and set default sink.
pacmd set-card-profile "$bluezcard" "$defaultprofile"
;;
"a" | "a2" | "a2d" | "a2dp" | "a2dp_sink")
# good audio quality for listening music.
pacmd set-card-profile "$bluezcard" "a2dp_sink"
;;
"h" | "hsp" | "hfp" | "head" | "headset" | "headset_head_unit")
# shitty audio quality, but allows to use microphone.
pacmd set-card-profile "$bluezcard" "headset_head_unit"
;;
*)
die "$op: unknown operation"
;;
esac
refreshbar