bluetooth pair and discover
This commit is contained in:
parent
c2fa015bee
commit
f789944f34
1 changed files with 32 additions and 8 deletions
|
@ -1,10 +1,11 @@
|
||||||
#!/bin/sh -x
|
#!/bin/sh -x
|
||||||
|
# Created by λmolinae
|
||||||
|
|
||||||
checkstate() {
|
checkstate() {
|
||||||
if [ "$(bluetoothctl show | grep "Powered: yes")" ]; then
|
if [ "$(bluetoothctl show | grep "Powered: yes")" ]; then
|
||||||
echo " ON"
|
echo " Bluetooth ON"
|
||||||
else
|
else
|
||||||
echo " OFF"
|
echo " Bluetooth OFF"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +16,6 @@ switchstate() {
|
||||||
notify-send "Bluetooth" "Bluetooth is disabled"
|
notify-send "Bluetooth" "Bluetooth is disabled"
|
||||||
;;
|
;;
|
||||||
" OFF")
|
" OFF")
|
||||||
echo "Bluetooth is enabled"
|
|
||||||
bluetoothctl power on
|
bluetoothctl power on
|
||||||
notify-send "Bluetooth" "Bluetooth is enabled"
|
notify-send "Bluetooth" "Bluetooth is enabled"
|
||||||
;;
|
;;
|
||||||
|
@ -24,13 +24,16 @@ switchstate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
scandevices() {
|
scandevices() {
|
||||||
|
# https://github.com/bluez/bluez/issues/826
|
||||||
|
notify-send "Bluetooth" "Scanning for devices"
|
||||||
bluetoothctl --timeout 5 scan on
|
bluetoothctl --timeout 5 scan on
|
||||||
devices=$(bluetoothctl devices | awk '{$1=$2=""; print substr($0,3)}')
|
devices=$(bluetoothctl devices | awk '{$1=$2=""; print substr($0,3)}')
|
||||||
if [ -z "$devices" ]; then
|
if [ -z "$devices" ]; then
|
||||||
notify-send "Bluetooth" "Error: No devices were found"
|
notify-send "Bluetooth" "Error: No devices were found"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# TODO: Remove previously connected devices.
|
||||||
selection="$(printf "%s\n" "$devices" | fuzzel -d -p "Available devices: ")"
|
selection="$(printf "%s\n" "$devices" | fuzzel -d -p "Available devices: ")"
|
||||||
if [ -n "$selection" ]; then
|
if [ -n "$selection" ]; then
|
||||||
mac=$(bluetoothctl devices | grep "$selection" | awk '{print $2}')
|
mac=$(bluetoothctl devices | grep "$selection" | awk '{print $2}')
|
||||||
|
@ -39,9 +42,30 @@ scandevices() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
case $(printf "%s\n" " Connect Device" " Change State" | fuzzel -d) in
|
toggledisc() {
|
||||||
" Connect Device")
|
if [ "$(bluetoothctl show | grep "Discoverable: yes")" ]; then
|
||||||
scandevices ;;
|
bluetoothctl discoverable off
|
||||||
|
notify-send "Bluetooth" "Discoverable off"
|
||||||
|
else
|
||||||
|
bluetoothctl discoverable on
|
||||||
|
notify-send "Bluetooth" "Set device as discoverable for 3 minutes"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
togglepair() {
|
||||||
|
if [ "$(bluetoothctl show | grep "Pairable: yes")" ]; then
|
||||||
|
bluetoothctl pairable off
|
||||||
|
notify-send "Bluetooth" "Pairable off"
|
||||||
|
else
|
||||||
|
bluetoothctl pairable on
|
||||||
|
notify-send "Bluetooth" "Device is now pairable"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
case $(printf "%s\n" " Connect Device" " Toggle discoverable" " Toggle Pairable" " Change State" | fuzzel -d) in
|
||||||
|
" Connect Device") scandevices ;;
|
||||||
|
" Toggle discoverable") toggledisc ;;
|
||||||
|
" Toggle Pairable") togglepair ;;
|
||||||
" Change State") switchstate ;;
|
" Change State") switchstate ;;
|
||||||
*) exit ;;
|
*) exit ;;
|
||||||
esac
|
esac
|
||||||
|
|
Loading…
Add table
Reference in a new issue