Contribute
Register

Workaround for Bluetooth Mouse/Keyboard Battery Drain

Status
Not open for further replies.
Joined
Feb 7, 2011
Messages
7
Motherboard
Gigabyte Z390 DESIGNARE
CPU
Intel i7 8700
Graphics
Radeon RX580
Mobile Phone
  1. Android
The Problem:

My bluetooth mouse and keyboard's battery are draining too quickly. I'm having to charge them every few days.

My Setup:

I am using a USB BT Adapter (ASUS BT400). I have an Apple Magic Keyboard and Magic Mouse 2. My computer is set not to sleep.

My Solution:

I wrote a shell script to disconnect the keyboard and mouse after 10 minutes of non-use. This seems to have fixed the problem for me. I thought I would share the script in case it was helpful to others. The script uses blueutil (install using homebrew - https://brew.sh) to do most of the heavy lifting.

After the keyboard/mouse disconnect, I simply reconnect them by pressing a key on the keyboard and clicking the mouse.

How to Install & Set Up:

Please only attempt this if you know your way around the Mac's terminal and command line. With that said, I will try to make this as simple as possible.
  1. Download the attached zip file and unzip. Move the folder to your desktop.
  2. Launch Terminal.app
  3. Install blueutil by typing brew install blueutil in the terminal.
  4. Once installed, list all of your paired devices by typing blueutil --paired
  5. These are all of your bluetooth devices that will automatically be disconnected upon idle. If that is OK then you can skip the next step. Otherwise you will need to edit the script to disconnect only particular devices/
  6. (Optional) - Edit the shell script (disconnect_bluetooth_devices.sh) using your text editor of choice. You will need to comment out the Automatic method and uncomment and edit the Manual method. The instructions are in the script. Save your changes.
  7. Create a scripts folder in your home directory mkdir ~/scripts
  8. Move the shell script to your scripts folder
    mv ~/Desktop/bluetooth_scripts/disconnect_bluetooth_devices.sh ~/scripts/
  9. Time to test the script /bin/zsh ~/scripts/disconnect_bluetooth_devices.sh
  10. There shouldn't be any errors. If there are, please re-check the installation instructions.
  11. Now, If you stop using your keyboard and mouse for approximately 11 minutes, they will disconnect.
  12. (Optional) Do this step if you would like the script to run automatically when you log in to your computer.
  13. Type whoami in the terminal. This is your user name.
  14. Edit the plist (com.futility.loginscript.plist) using your text editor of choice.
  15. Replace YOUR_USER_NAME with your actual user name. This is case sensitive. Save your changes.
  16. Move the script to your LaunchAgents folder
    mv ~/Desktop/bluetooth_scripts/com.futility.loginscript.plist ~/Library/LaunchAgents/
  17. Log out (command-shift-Q) and log back in again.

Conclusion:

This has been thoroughly tested on macOS Catalina. I hope this is helpful to you. I am open to any suggestions and improvements.


--FUT1L1TY

EDIT 1 - 7/16/2020: v.1.1 added new test flag (--test)

EDIT 2 - 7/18/2020: v.1.2 bug fixes :(

EDIT 3 - 7/20/202: I found the actual fix. Will post soon...

EDIT 4 - 9/27/2020: Version 1.4 with updated instructions

EDIT 5 - 2/27/2022: Version 2.0 now works with Monterey
(Be sure to update to the latest version of blueutil v2.9 or higher) -> brew upgrade blueutil
 

Attachments

  • bluetooth_scripts.zip
    3.1 KB · Views: 39
Last edited:
What would the actual fix be? I am facing the same issue
 
My apologies for taking so long. I have updated the original post. Please let me know if this works for you.
 
Thank you so much FUT1L1TY ! I'm having the same issue and your script is working like a charm for me to resolve the problem :)
 
I have found this drain issue to occur only with Intel Wifi + Bluetooth Cards (IntelBluetoothFirmware.kext). Once the Broadcom card arrived and I swapped it, the battery drain stopped.
 
Thanks for that information WizMeister, actually, it's true, I'm using an Intel Bluetoothe device (0x8087:0x0AAA) with the IntelBluetoothFirmware.kext. I will follow that issue to the dev team.
 
WizMeister, would you mind sharing the Broadcom device you are using on with hardware board ?
 
Initially I ordered this:


But the motherboard antennae connectors would not plug safely on the card’s connectors. They supply a plastic piece that keeps them in place but Bluetooth signal appeared to be extremely low and WiFi was glitchy. The seller bummed me when I told them to refund me because they first wanted me to send it back to China untracked.

So I ordered these which I have used on other builds as well and I consider to be the golden standard for itx motherboards with NGFF slot:

Card:

Adaptor:

You need to make sure your motherboard supports it because some of them do not accept anything else than Intel cards.

Also because of the height of the card and adapter, you will not be able to close the cover of the WiFi card of the motherboard (that’s the problem I wanted to solve with the first card I bought but meh, no one can see that particular area of the motherboard and I prefer the antennae having a great connection to the card to maximize the signal)
 
Hi @FUT1L1TY - thanks for making this script, seems to be exactly what I need as my keyboard battery dies in 4-5 days. I'm just having 2 issues with the script, 1st being:
...scripts/disconnect_bluetooth_devices.sh:[:63: unknown condition: -eq
- this one I managed to fix by adding [[ ]] instead of [ ] on line 63

and 2nd issue being:
(standard_in) 1: parse error
(standard_in) 2: parse error
- this one should be something related to "bc -l" but I still wasn't able to fix it.

Any chance you could look into those errors?
Thanks!
 
The script should work as is but I've only tested it using zshell. Is zshell your default shell? Try the following in the terminal.

% echo $SHELL /bin/zsh % /bin/zsh --version zsh 5.7.1 (x86_64-apple-darwin19.0)

Be sure to run the script as follows

% /bin/zsh /path/to/disconnect_bluetooth_devices.sh 600
 
Last edited:
Status
Not open for further replies.
Back
Top