Last active
April 19, 2020 06:08
-
-
Save rajeshisnepali/74eb8e290f497be98cea5c962f0e5d5c to your computer and use it in GitHub Desktop.
toggle bluetooth connection (on/off) & connect devices (connect/disconnect) in an easy way
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# toggle bluetooth connection (on/off) & connect devices (connect/disconnect) | |
# run "bluetoothctl" to find the MAC address of your device. | |
# default MAC (Airdots) | |
MAC="00:00:00:00:00:00" | |
enable() { | |
rfkill unblock bluetooth | |
} | |
disable() { | |
rfkill block bluetooth | |
} | |
on() { | |
echo -e "power on \nquit" | bluetoothctl | |
} | |
off() { | |
echo -e "power off \nquit" | bluetoothctl | |
} | |
c() { | |
MAC=${1:-${MAC}} | |
if ! hcitool con | grep -q "$MAC" | |
then | |
echo -e "connect $MAC \nquit" | bluetoothctl | |
fi | |
} | |
d() { | |
MAC=${1:-${MAC}} | |
if hcitool con | grep -q "$MAC" | |
then | |
echo -e "disconnect $MAC \nquit" | bluetoothctl | |
fi | |
} | |
$@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment