- Joined
- Feb 7, 2011
- Messages
- 7
- Motherboard
- Gigabyte Z390 DESIGNARE
- CPU
- Intel i7 8700
- Graphics
- Radeon RX580
- Mobile Phone
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.
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
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.
- Download the attached zip file and unzip. Move the folder to your desktop.
- Launch Terminal.app
- Install blueutil by typing brew install blueutil in the terminal.
- Once installed, list all of your paired devices by typing blueutil --paired
- 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/
- (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.
- Create a scripts folder in your home directory mkdir ~/scripts
- Move the shell script to your scripts folder
mv ~/Desktop/bluetooth_scripts/disconnect_bluetooth_devices.sh ~/scripts/ - Time to test the script /bin/zsh ~/scripts/disconnect_bluetooth_devices.sh
- There shouldn't be any errors. If there are, please re-check the installation instructions.
- Now, If you stop using your keyboard and mouse for approximately 11 minutes, they will disconnect.
- (Optional) Do this step if you would like the script to run automatically when you log in to your computer.
- Type whoami in the terminal. This is your user name.
- Edit the plist (com.futility.loginscript.plist) using your text editor of choice.
- Replace YOUR_USER_NAME with your actual user name. This is case sensitive. Save your changes.
- Move the script to your LaunchAgents folder
mv ~/Desktop/bluetooth_scripts/com.futility.loginscript.plist ~/Library/LaunchAgents/ - 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:
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
Last edited: