2024-09-22 16:31:58 -05:00
|
|
|
#!/bin/bash
|
2022-01-02 22:35:07 -06:00
|
|
|
|
2021-04-19 13:54:49 -05:00
|
|
|
# Toggles bluetooth on a Linux system. Make sure that you have bluetoothctl installed.
|
|
|
|
# I use it with a shortcut.
|
2024-09-22 16:31:58 -05:00
|
|
|
#
|
2021-04-19 13:54:49 -05:00
|
|
|
|
2024-09-22 21:42:25 -05:00
|
|
|
DONGLE_MAC=$(bluetoothctl list | grep dongle | awk '{print $2}')
|
|
|
|
INTERNAL_MAC=$(bluetoothctl list | grep internal | awk '{print $2}')
|
|
|
|
|
|
|
|
if [ -z $DONGLE_MAC ]; then
|
|
|
|
DEVICE_MAC=$INTERNAL_MAC
|
2021-04-19 13:54:49 -05:00
|
|
|
else
|
2024-09-22 21:42:25 -05:00
|
|
|
DEVICE_MAC=$DONGLE_MAC
|
|
|
|
echo -e "select $INTERNAL_MAC\npower off" | bluetoothctl
|
2024-09-22 16:31:58 -05:00
|
|
|
fi
|
|
|
|
|
2024-09-22 21:42:25 -05:00
|
|
|
if [ $(bluetoothctl show $DEVICE_MAC | grep Powered | grep -c yes) == 1 ]; then
|
|
|
|
echo -e "select $DEVICE_MAC\npower off" | bluetoothctl
|
2024-09-22 16:31:58 -05:00
|
|
|
else
|
|
|
|
if [ $(rfkill --output-all | grep bluetooth | grep -c blocked) != 0 ]; then
|
2021-12-08 19:35:57 -06:00
|
|
|
rfkill unblock bluetooth
|
|
|
|
fi
|
2024-09-22 21:42:25 -05:00
|
|
|
echo -e "select $DEVICE_MAC\npower on" | bluetoothctl
|
2024-09-22 16:31:58 -05:00
|
|
|
fi
|