1
0
mirror of https://github.com/kmein/niveum synced 2026-03-16 10:11:08 +01:00
Files
niveum/packages/scripts/dmenubluetooth.sh

56 lines
1.8 KiB
Bash
Raw Permalink Normal View History

2020-09-14 18:25:51 +02:00
#!/bin/sh
# UI for connecting to bluetooth devices
2020-09-15 20:33:08 +02:00
set -efu
2020-09-14 18:25:51 +02:00
bluetooth_notify() {
notify-send --app-name=" Bluetooth" "$@"
}
2020-09-15 20:33:08 +02:00
chose_device() {
# the output from `bluetoothctl {paired-,}devices` has a first column which always contains `Device` followed by a MAC address and the device name
cut -d ' ' -f2- | dmenu -i -l 5 -p "Bluetooth device"
}
bluetoothctl scan on &
case "$(printf "pair\nconnect\ndisconnect" | dmenu -i)" in
pair)
chosen="$(bluetoothctl devices | chose_device)"
chosen_name="$(echo "$chosen" | cut -d ' ' -f2-)"
bluetooth_notify "$chosen_name" "Pairing ..."
if bluetoothctl pair "$(echo "$chosen" | cut -d ' ' -f1)"; then
bluetooth_notify "$chosen_name" "Paired with device."
else
test "$chosen" && bluetooth_notify "$chosen_name" "Failed to pair with device."
fi
;;
connect)
chosen="$(bluetoothctl paired-devices | chose_device)"
chosen_name="$(echo "$chosen" | cut -d ' ' -f2-)"
bluetooth_notify "$chosen_name" "Trying to connect ..."
2020-09-14 18:25:51 +02:00
2020-09-15 20:33:08 +02:00
if bluetoothctl connect "$(echo "$chosen" | cut -d ' ' -f1)"; then
bluetooth_notify "$chosen_name" "Connected to device."
else # something was selected but it didn't work
test "$chosen" && bluetooth_notify "$chosen_name" "Failed to connect to device."
fi
;;
2020-09-14 18:25:51 +02:00
2020-09-15 20:33:08 +02:00
disconnect)
chosen="$(bluetoothctl paired-devices | chose_device)"
chosen_name="$(echo "$chosen" | cut -d ' ' -f2-)"
2020-09-14 18:25:51 +02:00
2020-09-15 20:33:08 +02:00
bluetooth_notify "$chosen_name" "Disconnecting ..."
2020-09-14 18:25:51 +02:00
2020-09-15 20:33:08 +02:00
if bluetoothctl disconnect "$(echo "$chosen" | cut -d ' ' -f1)"; then
bluetooth_notify "$chosen_name" "Disconnected from device."
else # something was selected but it didn't work
test "$chosen" && bluetooth_notify "$chosen_name" "Failed to disconnect from device."
fi
;;
esac