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 16:31:58 -05:00
|
|
|
BLUETOOTH_DEVICE=$(bluetoothctl list | grep dongle | awk '{print $2}')
|
|
|
|
if [ -z $BLUETOOTH_DEVICE ]; then
|
|
|
|
BLUETOOTH_DEVICE=$(bluetoothctl list | head -1 | awk '{print $2}')
|
2021-04-19 13:54:49 -05:00
|
|
|
else
|
2024-09-22 16:31:58 -05:00
|
|
|
BLUETOOTH_DEVICE_OTHER=$(bluetoothctl list | grep internal | awk '{print $2}')
|
|
|
|
echo -e "select $BLUETOOTH_DEVICE_OTHER\npower off" | bluetoothctl
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $(bluetoothctl show $BLUETOOTH_DEVICE | grep Powered | grep -c yes) == 1 ]; then
|
|
|
|
echo -e "select $BLUETOOTH_DEVICE\npower off" | bluetoothctl
|
|
|
|
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 16:31:58 -05:00
|
|
|
echo -e "select $BLUETOOTH_DEVICE\npower on" | bluetoothctl
|
|
|
|
fi
|