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.
On Ventura 13.3.1 and encountering small issue:
administrator@Mac-Pro ~ % /usr/local/sbin/sleepwatcher --verbose -w ~/.wakeup
Bluetooth on, restarting ...
Failed to switch bluetooth power off in 10 seconds
Couldn't stop Bluetooth Module
Bluetooth Module
started
Successfully restarted Bluetooth
sleepwatcher: wakeup: /Users/administrator/.wakeup: 0
It works nicely... but, it has about a 10 sec wait time after waking until the bluetooth starts working. Would be nice to iron that out if at all possible.
I tried editing the first part of the command in the .\wakeup script out:
($("$BT" -p 0) &> /dev/null && echo "Bluetooth Module stopped") || (err "Couldn't stop Bluetooth Module" && exit 1)
, so that it didn't try to turn Bluetooth off, skipping that failure and 10 sec wait, but Bluetooth didn't work after waking it up.
So even though theres that failure in the verbose output, seems to function with the 10 second delay.
Any ideas to speed it up?
Thank you!!