vim, gitconfig, update.sh
[dotfiles_afify.git] / .scripts / bluetooth_connect
blobedd3b4ef6688e575fcab321362cadd0f70f4bc14
1 #!/bin/sh
3 device='FC:A8:9A:57:A4:8A'
4 device_sink='FC_A8_9A_57_A4_8A'
5 device_name="JBL Headset"
7 force(){
8 pulseaudio -k
9 # usermod -a -G bluetooth $USER
10 # sv restart dbus
11 dmenu -P -p "sudo " | sudo -S sh -c\
12 "rfkill unblock bluetooth
13 sv stop bluetoothd
14 sv start bluetoothd"
15 # sudo rfkill block wlan && sudo modprobe -r btusb && sleep 10 && sudo modprobe btusb && systemctl --user restart pulseaudio && sudo systemctl restart bluetooth
16 # modprobe btusb ;sudo systemctl start bluetooth
19 check_bluetooth(){
20 bstatus=$(pgrep bluetoothd)
21 bl_s=$(rfkill -rn | awk '/bluetooth/ {print $4}')
22 if [ ! "$bstatus" ] || [ "$bl_s" != "unblocked" ]; then
23 force
27 connect_device(){
28 is_connected=$(bluetoothctl info $device | awk '/Connected/ {print $2}')
29 if [ ! "$is_connected" = "yes" ]; then
30 bluetoothctl power off
31 bluetoothctl power on
32 bluetoothctl disconnect $device
33 bluetoothctl pair $device
34 bluetoothctl connect $device
35 bluetoothctl trust $device
39 change=$(pacmd set-card-profile bluez_card.$device_sink a2dp_sink |\
40 grep -o "Failed")
41 if [ "$change" = "Failed" ]; then
42 force
43 jbl
44 else
45 pacmd set-default-sink bluez_sink.$device_sink.a2dp_sink
46 inputs=$(pacmd list-sink-inputs | awk '$1 == "index:" {print $2}')
47 for apps in $inputs; do
48 pacmd move-sink-input "$apps" bluez_sink.$device_sink.a2dp_sink
49 done
52 check_bluetooth
53 connect_device