Skip to content

Instantly share code, notes, and snippets.

@rajeshisnepali
Last active April 19, 2020 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajeshisnepali/74eb8e290f497be98cea5c962f0e5d5c to your computer and use it in GitHub Desktop.
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
#!/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