There is a program called [SleepWatcher] (http://www.bernhard-baehr.de/) that monitors sleep, wakeup and idleness of a Mac. To restart Bluetooth everytime your Mac comes up from sleep, you have to tell SleepWatcher to execute the script from above automatically. Restarting Bluetooth takes approximately 2s, so it doesn't attract negative attention.
The script makes use of BlueUtil, so you have to install it too. (I'm assuming you have HomeBrew installed)
brew install sleepwatcher
brew install blueutil
To make use of SleepWatcher, you have to put the gist to ~/.wakeup (For more information about sleepwatcher open terminal and insert: man sleepwatcher)
After you put your script to ~/.wakeup do the following:
chmod +x ~/.wakeup
Now you can test the script. Add the following command to your terminal:
/usr/local/sbin/sleepwatcher --verbose -w ~/.wakeup
Now you have to enter sleep mode and wakeup your Mac again. After that, you should see the following console output:
Bluetooth on, restarting ...
Bluetooth Module stopped
Bluetooth Module started
Successfully restarted Bluetooth
sleepwatcher: wakeup: /Users/ralph/.wakeup: 0
If it works, you can set up launchd to start sleepwatcher at login by using brew services.
brew services start sleepwatcher
For debugging purposes you can enter Console App and search for "bt_restarter". Maybe there are some messages indicating a problem.
Pulling out the big guns
/usr/local/bin/blueutil -p 0
alone didn't work for me, I did this:~/.local/bin/restart-bluetooth
:It's only sometimes that my bluetooth doesn't reconnect after sleep & wake (may be related to docking to my Thunderbolt Display) and I don't know how to immediately cause the problem, so I don't know what about that process is required. Obviously some of it is superfluous, but if I run that script my bluetooth dies and comes right back, so I know it's working well enough.
If someone can pare it down to just what's necessary I'd love to hear the explanation (ping me @coolaj86).