Automatically toggle Bluetooth depending on your power source
by postbreak
One of my biggest complaints about using my Macbook in clamshell mode is toggling bluetooth back on to use both my mouse and keyboard. I am one of the many Mac users who attach a large monitor while at my desk and then turn bluetooth off while on battery. Usually when I get home I plug just about every connection I can into my Macbook and then curse at the fact that I have absolutely no way to toggle bluetooth on since my keyboard and mice use it.
So after a year or so of searching I finally got a working script to automatically enable and disable bluetooth depending on the power source. This script is smart in that when it disables bluetooth, you can turn bluetooth back on and the script won’t keep shutting it off. This was one of the biggest hurdles for me to overcome. Luckily I got help. My good friend Bill from cubicle17.com and Chad helped me work this into shape. Specifically Bill helped turn the Applescript into a Bash script which reduced the ram usage exponentially (Applescript gobbled up 11MB vs Bash using 600kb).
The script can be viewed here. Simply download it or copy and paste into a new file and make sure to chmod it so it’s executable.
There is only one requirement to run this script, an application called blueutil. You can download blueutil here, however, I have it mirrored on my site here in case the authors website ever disappears. I am currently looking into a way to implement the code it uses into my script so blueutil is not required. Simply unzip and run the installer. You may have to reboot or log in and out after installation.
So to get this script to run the way it’s designed you need it to run all the time. To do this you should check out the application Lingon. First download it here. Then simply fill out the details like I did below.
I have had this script running for a few days now and haven’t seen any notable glitches or memory leaks. If you have any problems or questions feel free to leave a comment or send me an email (located in the contact page).
well, that’s awesome!
i just can’t get it to work as an agent running in the background. the script is executable and is working fine as long as i run it in a terminal window – bluetooth switches off/on accordingly to ac/battery power.
but creating an agent with lingon doesn’t seem to work – bluetooth not switching off/on.
i can see ‘bash’ -> ‘sleep’ entries in activity monitor though. i’m confused.
what am i doing wrong?
mac os x 10.5.7 on macbook 2,1
Do you have the command setup like I have in the screenshot? “./path-to-script/monitor_bt.sh” I’m not sure why it wouldn’t be working if it’s setup like that. You may have to restart to see the settings after you change them as well.
yep. command setup exactly like your screenshot. restart done.
maybe there’s something else i’m not seeing right now. it’s weird.
thanks a lot though for sharing this script!
Let me know if you find the problem. I have it running just like this guide and it works just fine. I have no idea what could be causing the issue.
Marco Polo will do this and many other context switching automated tasks.
http://www.symonds.id.au/marcopolo/
blueutil not required
http://www.axoniclabs.com/Bluetoggle/