bnsiqa
Last Updated: March 12, 2017
·
82
· mroach_
16107140 10100651592874953 393703796820975529 o

macOS battery life test with safe sleep at defined threshold

I replaced the battery in my 5 year old MacBook Pro and had issues with it shutting down on its own at say 50% and then the battery indicator on the side of the system would say 0%. Then after plugging it in and booting, the status did indeed say 0% battery, but then after a few minutes it'd go back up to 50-something percent and charge normally. Despite resetting the SMC and PRAM, something's awry. Either the new battery is defective or my MacBook's hardware is having a problem reading charge levels.

I wanted to do battery run time tests and log the load on the battery and its output voltage to debug this or at least be able to return the new battery with explanation. However I didn't want to just run the computer to death since that's bad for the battery. I wanted it to run down to 20% then put itself to sleep. It can use caffeinate to keep the system from going to sleep. So, a quick bash script later and it's done!

https://github.com/mroach/misc/blob/master/scripts/battery_life_test.sh

Screen Shot 2017-03-12 at 10.21.22.png