Set a shortcut to toggle bluetooth on or off
Is there a way to do this without installing extra packages?
You can control whether your bluetooth signal is enabled with rfkill
. Wrapping this in a little Bash conditional allows you to toggle the state easily:
#!/bin/bash
if rfkill list bluetooth | grep -q 'yes$' ; then
rfkill unblock bluetooth
else
rfkill block bluetooth
fi
You could save the above in a script file anywhere (e.g. ~/bin/toggle-bluetooth
) and make it executable (chmod +x FILENAME
) to be able to bind that command to a keyboard shortcut in the system settings.
Alternatively, you can put it in a single line bash
command and directly paste that into the shortcut:
bash -c "if rfkill list bluetooth|grep -q 'yes$';then rfkill unblock bluetooth;else rfkill block bluetooth;fi"