-1

Im using ubuntu with cinnamon and im tired of not having a bluetooth switch, and having to use rfkill to turn BT off. For now, i use blueman to turn BT on and manage devices and connections, and I use rfkill on my terminal to turn it back off after im done using it. I wanted to create a clickable macro (ie : as a cinnamon applet that would display on my taskbar) that rfkills on and off BT.

My question is : is there a command of rfkill that lets you simply invert a device's state (that is unblock if blocked and blocked if unblocked) ?

Bruh
  • 315

1 Answers1

1

There is no invert flag in rfkill and there is no alternative cli tool that can do this. You can write a small script like the one below for it and have a keybinding initiate the script.

Note : You will need to add your user to sudoers file to run rfkill without password.

#!/bin/bash
BTDEVNO=1
currentState=$(rfkill list $BTDEVNO)
if [[ $currentState =~ ": no" ]]; then
    echo "Unblocked, going to block";
    sudo rfkill block $BTDEVNO;
else
    echo "Blocked, going to unblock";
    sudo rfkill unblock $BTDEVNO;
fi

Edit - About sudoers (made by Bruh) :

To add rfkill to the sudoers list, type sudo visudo and then add the following at the end of the file, under the %sudo line :

user_name : ALL=(ALL) NOPASSWD : /usr/sbin/rfkill

This will allow rfkill to run without the need of the sudo password.

Edit 2 - Slight change to the script (Made by Bruh) :

If the scipt seems to be always seeing BT blocked despite a manual rfkill list showing it unblocked, try replacing the if statement by the following :

if echo $currentState | grep 'Bluetooth Soft blocked: no'; then
Bruh
  • 315