mirror of
https://github.com/SinTan1729/random.git
synced 2024-12-24 20:38:36 -06:00
28 lines
771 B
Bash
28 lines
771 B
Bash
#!/bin/bash
|
|
|
|
# Toggles bluetooth on a Linux system. Make sure that you have bluetoothctl installed.
|
|
# I use it with a shortcut.
|
|
|
|
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
|
|
else
|
|
DEVICE_MAC=$DONGLE_MAC
|
|
fi
|
|
|
|
if [ $(bluetoothctl show $DEVICE_MAC | grep Powered | grep -c yes) == 1 ]; then
|
|
echo -e "select $DEVICE_MAC\npower off" | bluetoothctl
|
|
else
|
|
if [ $(rfkill --output-all | grep bluetooth | grep -c blocked) != 0 ]; then
|
|
rfkill unblock bluetooth
|
|
fi
|
|
echo -e "select $DEVICE_MAC\npower on" | bluetoothctl
|
|
fi
|
|
|
|
if ! [ -z $DONGLE_MAC ]; then
|
|
sleep 0.5
|
|
echo -e "select $INTERNAL_MAC\npower off" | bluetoothctl
|
|
fi
|
|
|