-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautobluetooth
executable file
·39 lines (31 loc) · 1.2 KB
/
autobluetooth
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
#!/usr/bin/bash
# The below is the original file made in 2022. Ah, the times go by...
## This file was generated by ChatGPT Dec 15 Version.
#
## Check if Bluetooth is enabled
#if not bluetoothctl show | grep -q "Powered: yes"
# echo "Bluetooth is not enabled. Please enable Bluetooth and try again."
# return 1
#end
#
## Get the MAC address of the headset
#set -l headset_mac (bluetoothctl devices | grep -Eo "([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2})" | head -1)
#
## Connect to the headset
#bluetoothctl connect $headset_mac
# BEGIN 17 may 2024 addition:
which bluetoothctl || sudo pacman -S bluez
bluetoothctl scan on
systemctl enable bluetooth --now
# END
if ! bluetoothctl show | grep -q "Powered: yes"; then
notify-send "Bluetooth is not enabled. Please enable Bluetooth and try again."
exit 1
fi
headset_mac=$(bluetoothctl devices | grep -Eo "([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2})" | head -1)
if [ -z "$headset_mac" ]; then
notify-send "No Bluetooth devices found. Please make sure your headset is discoverable."
exit 1
fi
selected_headset=$(bluetoothctl devices | rofi -dmenu -p "Select Bluetooth headset" | grep -Eo "([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2})")
bluetoothctl connect "$selected_headset"