17

Is it possible to tweak the % that I get warning of low battery for my Magic Mouse 2?

I currently only get it at 2% at which point it's very close to dying so I have to stop what I'm doing and plug it in. A reminder about 10-15% would allow me to plug it in the next time I have a natural break.

  • Good question. To bad there is no answer – Martin Dec 22 '16 at 6:59
10

For those willing to copy and run a bash script and add a cron job, here is a complete solution that is free and current (as of June 2018) and requires no programming (I've done that part for you), just a little system administration:

Save this to a bash script like ~/.mouse-battery-check.sh:

#!/usr/bin/env bash
PATH=/usr/local/bin:/usr/local/sbin:~/bin:/usr/bin:/bin:/usr/sbin:/sbin

# actual battery level
BATT=`ioreg -c AppleDeviceManagementHIDEventService -r -l | grep -i mouse -A 20 | grep BatteryPercent | cut -d= -f2 | cut -d' ' -f2`

# defaults to warn at 20%; accepts other number as 1st argument (useful for testing)
COMPARE=${1:-20}

if [ -z "$BATT" ]; then
  echo 'No mouse found.'
  exit 0
fi

if (( BATT < COMPARE )); then
  osascript -e "display notification \"Mouse battery is at ${BATT}%.\" with title \"Mouse Battery Low\""
fi

Open up Terminal and make the script executable:

chmod +x ~/.mouse-battery-check.sh

Now you can test that the script sends a desktop notification by running it when your BlueTooth mouse is connected (this tests for battery less than 101%, so it should always send a notification):

~/.mouse-battery-check.sh 101

To test again with the default setting (20%):

~/.mouse-battery-check.sh

When a BlueTooth mouse is not detected, the script will return, "No mouse found."

Checking Automatically

Now to test periodically and notify you automatically, add a new cron job:

env EDITOR=nano crontab -e

Add an entry like to check every 15 minutes:

*/15 * * * * cd ~ && bash ~/.mouse-battery-check.sh

(You can again pass the battery percentage as a parameter to the script here.)

Press Control+X then Y then Enter to exit the editor and save the cron job.

Acknowledgements

For battery check, this answer:

adjust battery-warning-level of magic mouse

For notification, this answer:

How can I trigger a Notification Center notification from an AppleScript or shell script?

For cron jobs, this blog:

https://ole.michelsen.dk/blog/schedule-jobs-with-crontab-on-mac-osx.html

  • This works perfectly for me whereas I never got BTT to work, thanks a lot for the great answer. I'm not sure if I should make it the accepted answer just because it's a bit more involved than a straightforward setting adjustment or GUI solution. – DEfusion Jun 13 '18 at 15:39
  • Incidentally a similar approach should work for Magic Keyboard. – Will Cain Jun 14 '18 at 12:38
6

There is a way!

Sadly you need BTT (Better Touch Tools) for this. BTT was free, but to support ongoing development there is now a pay-what-you-want license model starting at 5 USD. But afaik you can test it for free for some days.

How to set the notification:

  1. Start BTT → Menu bar → Preferences → Basic Settings → Check "Launch BTT on startup"
  2. Switch to Advanced settings (top left hand corner)
  3. Go to Mouse settings (top right hand corner)
  4. Under "General" at the bottom there is "Warn if battery level is lower than X %"
  5. Check the option and set your level.

btt screenshot

  • Thanks just installed it now, seems like the app does a lot more that I can poke around with. – DEfusion May 18 '17 at 10:25
  • Yes, the app is for me a must have! Window snapping, custom keystroke commands and so much more! – CodeBrauer May 19 '17 at 10:41
  • If you have a Magic Trackpad, BTT is absolutely essential. I couldn't live without it these days. – Kaitain 13 hours ago
-1

you can always download bitbar and just add some script to run, like this one https://github.com/kkunkel/OSX-Nagios.

  • 1
    Welcome to Ask Different and taking the time to post an answer! It's helpful to expand on your answer to further explain/clarify what you are attempting to communicate. It's also better to include the relevant points in this answer rather than just linking to another one. – Allan Jun 12 '18 at 13:34
  • This checks computer battery not magic mouse battery. – JBis Jun 12 '18 at 21:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .