| 1 | #!/bin/bash |
| 2 | |
| 3 | #bcn, Bluetooth Connect |
| 4 | |
| 5 | |
| 6 | device_amount=$(bluetoothctl devices | wc -l) |
| 7 | |
| 8 | if [[ $device_amount = 1 ]]; then |
| 9 | MAC=$(bluetoothctl devices | awk {'print $2'}) |
| 10 | [ -z $MAC ] && MAC=NoDeviceFound # Prevents accidental disconnect error |
| 11 | else |
| 12 | select=$(bluetoothctl devices | awk {'print $3'} | rofi -dmenu -l 10 -fn Monospace-15) |
| 13 | MAC=$(bluetoothctl devices | grep $select | awk {'print $2'}) |
| 14 | [ -z $MAC ] && MAC=NoDeviceFound # Prevents accidental disconnect error |
| 15 | fi |
| 16 | |
| 17 | connect=$(bluetoothctl info $MAC | grep Connected: | awk '{print $2}') |
| 18 | if [[ $connect = no ]]; then |
| 19 | notify-send "Attempting to connect to $select" |
| 20 | bluetoothctl connect $MAC || notify-send "Failed to Connect" |
| 21 | elif [[ $connect = yes ]]; then |
| 22 | notify-send "Attempting to disconnect $select" |
| 23 | bluetoothctl disconnect $MAC |
| 24 | fi |