You are not logged in.
Pages: 1
So I am trying to make a hotkey Fn+F6 to turn on and off my bluetooth. The problem is that ThinkWiki gives a script for init.d which have the status option. Without it, the action script only disables bluetooth as it never gets the status output string to check if it should enable or disable. This is not a major issue, however, I would like to get this working. Is there any other way to check if bluetooth is currently running and start/stop it all from 1 script?
The one they have is:
#!/bin/bash
# Bluetooth enable/disable script
/etc/init.d/bluetooth status
if [ "$?" -ne 0 ]; then
/etc/init.d/bluetooth start > /dev/null
echo enabled > /proc/acpi/ibm/bluetooth
echo "Bluetooth enabled"
else
/etc/init.d/bluetooth stop > /dev/null
echo disabled > /proc/acpi/ibm/bluetooth
echo "Bluetooth disabled"
fi
And the event controller is (not that it matters):
event=ibm/hotkey HKEY 00000080 00001006
action=/etc/acpi/actions/bluetooth
Last edited by bgalakazam (2010-06-09 23:42:37)
Offline
"ls /var/run/daemons" gives a list of currently running daemons, provided they are launched in the standard Arch way
Online
So how would the if statement change then?
Offline
if [ -f /var/run/daemons/bluetooth ]
and you will want to change all those /etc/init.d/...
Online
Right now my action script is:
#!/bin/bash
# Bluetooth enable/disable script
if [ -f /var/run/daemons/bluetooth ]; then
/etc/rc.d/bluetooth stop > /dev/null
echo disabled > /proc/acpi/ibm/bluetooth
echo "Bluetooth disabled"
else
/etc/rc.d/bluetooth start > /dev/null
echo enabled > /proc/acpi/ibm/bluetooth
echo "Bluetooth enabled"
fi
I have tried changing the if and else functions, but to no avail. I am also restarting acpid so it is not that.
Any ideas?
Offline
Are you running the script as root, aren't you?
Mortuus in anima, curam gero cutis
Offline
Why not use one of the already existing control files?
BT=/proc/acpi/ibm/bluetooth
BT=/sys/devices/platform/thinkpad_acpi/bluetooth_enable
BTCAT=$(grep -c "status.*enabled" /proc/acpi/ibm/bluetooth)
BTCAT=$(cat /sys/devices/platform/thinkpad_acpi/bluetooth_enable)
case "$BTCAT" in
1) /etc/rc.d/bluetooth stop >/dev/null 2>&1
echo 0 > $BT (or echo disabled > $BT, depending on the control file you choose)
;;
0) ...
;;
esac
Maybe you should also introduce a test if the bluetooth daemon is running:
BTDAEMON=$(ls /var/run/daemons | grep -c bluetooth)
[[ $BTDAEMON = 1 ]] && /etc/rc.d/bluetooth stop
[[ $BTDAEMON = 0 ]] && /etc/rc.d/bluetooth start
As you're using a thinkpad, you can also use that on a hotkey:
#!/bin/sh
# /etc/acpi/handler.sh
BT=/sys/devices/platform/thinkpad_acpi/bluetooth_enable
BTCAT=$(cat $BT)
BTDAEMON=$(ls /var/run/daemons | grep -c bluetooth)
EVENT=$1\ $2\ $3\ $4
case "$EVENT" in
ibm*1006) # FN+F6
case "$BTCAT" in
1) [[ $BTDAEMON = 1 ]] && /etc/rc.d/bluetooth stop
echo 0 > $BT;;
0) [[ $BTDAEMON = 1 ]] && /etc/rc.d/bluetooth start
echo 1 > $BT;;
esac;;
esac
Regards,
demian
Last edited by demian (2010-06-08 09:54:27)
no place like /home
github
Offline
Pages: 1