One of my biggest complaints is not having the ability to toggle Bluetooth on and off based on my power source. I use my Macbook in clamshell mode, so turning Bluetooth back on with my Bluetooth keyboard and mouse is impossible. I have to wait for my Macbook to wake up, open the lid, and reach over to the trackpad and toggle Bluetooth on.
With some help, I was able to make the following script to toggle Bluetooth on when the machine is plugged in, and off when running on the battery. This script is smart in that it will not fight you if you turn Bluetooth on while on battery power. You can unplug the power, the script will turn Bluetooth off, and you can turn it back on and it will stay that way.
There is one requirement to use this application which is blueutil. (I have it mirrored on my site where I originally posted this; you can see my full guide there as well). Here's the script (remember to make it executable):
I have not noticed any memory leaks, and this only uses about 600KB of RAM to run with almost no CPU usage to call on pmset or blueutil. You can obviously change the sleep setting (which determines how long before the script runs again) to whatever you like.
[robg adds: I haven't tested this one.]
With some help, I was able to make the following script to toggle Bluetooth on when the machine is plugged in, and off when running on the battery. This script is smart in that it will not fight you if you turn Bluetooth on while on battery power. You can unplug the power, the script will turn Bluetooth off, and you can turn it back on and it will stay that way.
There is one requirement to use this application which is blueutil. (I have it mirrored on my site where I originally posted this; you can see my full guide there as well). Here's the script (remember to make it executable):
#! /bin/bash
PREVIOUS_SOURCE=$(pmset -g ps | perl -ne '/(w+) Power/ && print $1');
while [ 1 ]; do
CURRENT_SOURCE=$(pmset -g ps | perl -ne '/(w+) Power/ && print $1');
if [ $CURRENT_SOURCE != $PREVIOUS_SOURCE ]; then
PREVIOUS_SOURCE=$CURRENT_SOURCE
if [ $CURRENT_SOURCE = "AC" ]; then
blueutil on
else
blueutil off
fi
fi
sleep 5
done
Next you simply need to run the script at startup, which is easy enough to do with the free app Lingon.
I have not noticed any memory leaks, and this only uses about 600KB of RAM to run with almost no CPU usage to call on pmset or blueutil. You can obviously change the sleep setting (which determines how long before the script runs again) to whatever you like.
[robg adds: I haven't tested this one.]
•
[8,111 views]

