Introduction

Perhaps my 2010 MacBookPro is starting to feel its age? For some reasons it’s had a slew of Wi-Fi and Bluetooth related issues in recent months. The most recent is that after coming out of Sleep (standby) Bluetooth would remain in dreamland and refuse to function. In most cases I can’t turn it On or Off, or select any options or bring up context menus in the Bluetooth Preferences panel. Or if I can use the context menus, Connect and Disconnect don’t do much. It usually reports my external keyboard and trackpad are connected, but nothing works. It seems like the Bluetooth system has gone into a deep coma or died in its sleep.

I am about to install a Bluetooth 4.0 adapter, and perhaps the built-in BT has cottoned on, and is kicking up its feet in disgust? Truth is, if it wasn’t messing with the Wi-Fi connection so much in the past month (seems the two have been at war with each other), I’d not have considered adding an external BT adapter to begin with — more on that in another article. Here’s how to potentially resolve these issues of BT dyeing in its sleep.

Solution for Bluetooth failure after Sleep mode

The best solution I found was to unload and load the KEXT for the Bluetooth hardware. If you don’t know what a KEXT file is, don’t worry. Kind folks have provided an automated (scripted) way to deal with this. First step is to test whether this method actually resolves your Bluetooth failure after system sleep.

NB. In a few places these instructions assume you are using OS X Yosemite, as that’s the OS in which this Bluetooth issue commonly occurs. If you have at least OS X 10.8, you should be fine. The only relevant point is in the way .command files are handled in Finder.

1) Pre-test: First you’ll need to test this out. Run the following two lines of code in Terminal.app

You will be prompted for your password. Type it in (no text will appear when you type it, so just hit Return/Enter key after you type it in).

Now test out your Bluetooth peripherals. If they are working again, then the above solution works for you. So the next step is to automate it.

Automation of the fix:

There’s a few ways to do this. We’ll cover three. If you have Homebrew installed on your system, follow step 2A. If you don’t have Homebrew installed (and perhaps don’t even know what that is, except a DIY way to make beer) follow instructions at 2B. Or, alternatively, if you prefer to use Automator, follow instuctions at 2C.

The first two methods will install a neat little utility called Sleepwatcher. This gives you a means to have scripts, etc., run when your system sleep state changes in any way. The third method, using Automator, is less automated. It gives you a way to manually execute the command line entries you tested in step 1 above.

2 A) HOMEBREW METHOD (with Sleepwatcher)

Create a text file in your user home directory (or, for instance, in your Downloads folder) using a text editor. Paste in the following code:

Save the file with the name bt-fix.command

Execute the script

In Yosemite (and likely OS X 10.8 or later) you can now double-click .command the file in Finder, and it should execute.

You may need to make the script executable with the following command in Terminal.app

Unless you know how to change directory in Terminal over to where you saved your script, the easiest way to get the script name in there with the path is to just type the chmod a+x part into Terminal, add one space, and then drag the .command file from Finder to the Terminal window. That will automatically insert a reference to the file, with the full path.

2B) SCRIPT METHOD, NO HOMEBREW (with Sleepwatcher)

Create a text file in your user home directory (or, for instance, in your Downloads folder) using a text editor. Paste in the following code:

Save the file with the name bt-fix.command to a location that makes sense to you.

Execute the script

In Yosemite (and likely OS X 10.8 or later) you can now double-click .command the file in Finder, and it should execute.

You may need to make the script executable with the following command in Terminal.app

Unless you know how to change directory in Terminal over to where you saved your script, the easiest way to get the scriptname in there with the path is to just type the chmod a+x part into Terminal, add one space, and then drag the .command file from Finder to the Terminal window. That will automatically insert a reference to the file, with the full path.

2C) AUTOMATOR METHOD (without Sleepwatcher)

  1. Use Spotlight to find and run Automator
  2. Click “New Document” at bottom
  3. Choose “Application” for the new file type
  4. Click on “Utilities” from the list
  5. Double-Click “Run AppleScript”
  6. Replace (* Your script goes here *) with:

  • Press Play to test the automation. You will be propted for your password. Enter it.
  • Once done, save the file to somewhere convenient, such as your Desktop. File -> Save.

The Lazy Way

If you know nothing about Terminal, except that it sounds fatal, and all of the above seems to daunting and esoteric, you can just run the following application. I have bundled up solution 2B into an app that will do what’s required. Use at your own risk (I can’t think of any risks, but obviously the responsibility is yours, and not mine).

Download this App. Run it only once, if successful. Otherwise it will repeat certain steps and make a mess of your SleepWatcher configuration. Not a major to manually clean up, but worth avoiding. There is no reason to run it to completion more than once. It will install SleepWatcher, and give it the necessary commands to reload Bluetooth kexts after your computer comes out of sleep mode.

Credit

Credit for the ideas in this post go to the good folk involved in this discussion on apple.stackexchange.com