George MacKerron: code blog

GIS, software development, and other snippets

Fixing Bluetooth sleep issues with MacBook and Magic Trackpad

We have an old MacBook (the original white Intel model from 2006) running EyeTV as our telly.

Apple’s Magic Trackpad makes a handy remote control for this setup. Unfortunately, Bluetooth on the old MacBook is highly temperamental. Built-in Bluetooth regularly fails: out of the blue, the Mac decides that it has no Bluetooth module after all, puts a wavy line through the menu bar icon, and ignores the trackpad. The only fix for this is to shut the computer down, and leave it off for several minutes. This is annoying.

I had an old D-Link Bluetooth dongle (DBT-120), so I tried using this instead. This is better, in that the failure mode is less annoying. Using the dongle, the trackpad’s Bluetooth connection only fails after a prolonged sleep. It looks as if it’s still connected, with a dotted line across the Bluetooth icon, but it’s unresponsive. This can be fixed by simply unplugging and replugging the dongle. But that’s still a pain, and is rather a compromise of the ‘remote’ in remote control.

It turns out that the post-sleep unresponsiveness may also be fixed by restarting the Bluetooth daemon, by typing sudo killall blued in the Terminal.

This is good news, because we can automate this action using sleepwatcher.

If typing sudo killall blued in Terminal solves your Bluetooth issues after sleep, then you may want to use sleepwatcher too. (Note that after a sudo command, you may be asked for a password. Nothing will show up as you type, but that’s OK: just type your password and press Return).

To set up sleepwatcher to restart Bluetooth on wake, first type sudo su into your Terminal to gain admin rights.

Then paste in all of the following:

# install sleepwatcher
mkdir -p src
cd src
curl -O
tar xvzf sleepwatcher_2.2.tgz
cd sleepwatcher_2.2
mkdir -p /usr/local/sbin /usr/local/share/man/man8
cp sleepwatcher /usr/local/sbin
cp sleepwatcher.8 /usr/local/share/man/man8
# create wakeup file
echo '#!/bin/bash\nkillall blued' > /etc/rc.wakeup
# run sleepwatcher daemon at boot
sed -e /-V/d -e /-s/d \
  config/de.bernhard-baehr.sleepwatcher-20compatibility.plist \
  > /Library/LaunchDaemons/de.bernhard-baehr.sleepwatcher.plist
# all done

Restart, and you should find that blued is restarted on every wake.

Note that, using the Bluetooth dongle, the trackpad still cannot wake the MacBook from sleep. This is not such a problem for us, because we also have an Apple Remote, which can.


Written by George

October 11th, 2012 at 1:55 pm

Posted in Mac