Start and stop bluetooth service automatically as rfkill switch changes

bluetooth

I would like to start / stop bluetooth service automatically when I turn on / off rfswitch, is that possible ?

Best Answer

Yes. Assuming you have udev, something like the following would be a decent start:

# /etc/udev/rules.d/10-rfkill.rules
SUBSYSTEM=="rfkill", ATTR{type}=="wlan", RUN+="/usr/local/bin/toggle-blue"

And then:

#!/bin/bash
#/usr/local/bin/toggle-blue

if [ ${RFKILL_STATE} = 2 -o ${RFKILL_STATE} = 0 ]; then
    (
    /etc/rc.d/bluetooth stop
    ) &
else
    (
    /etc/rc.d/bluetooth start
    ) &
fi

See the relevant man pages for more info ... you can do a lot with udev rules (although it can be a little overwhelming to learn).

Related Question