Don't trust OSX on your battery charge level as it says little lie about it.

Real battery charge level can be accurately calculated based on battery current and designed amperage.

Posted by Gediminas Siutilas on November 30, 2014

Preface

Native OSX battery charge indicator tells you a little lie about fully charged battery. When it hits 100% as per native OSX battery charge indicator in fact your battery is charged for about 94-96% of full charge.

ChargeIndicator script calculates battery charge level based on battery max capacity and current battery capacity values. For example standart OSX battery indicator shows you 100% when your battery current capacity is 7800 mAh where max capacity for example is 8233 mAh which leads to ~94.7% of full battery charge (7800*100/8233).

Using this script you can monitor your battery charge level with more precise calculation and extend your battery lifespan by unplugging your AC power at the right time.

Basically it takes plus 10-15minutes to fully charged battery since OSX indicated 100% of full charge.

* If you downloaded ShellWrangler app this scripts will be packed along with the downloaded application.

Configuration

Configuration

This script use 96% as a borderline when you can safely unplug your AC power.

## configuration section
#@@@{Percentage for fully charged battery}
fullyCharged=96

isACPower() {
...

Fully charged battery threshold can be changed by replacing the value for 'fullyCharged' variable.

When battery reaches your configured bordeline for fully charged battery icon will be replaced to "✅" signaling that AC power can be detached.

Script:

Download
#!/bin/bash

#   ____ __        __ __ _      __                       __         
#  / __// /  ___  / // /| | /| / /____ ___ _ ___  ___ _ / /___  ____
# _\ \ / _ \/ -_)/ // / | |/ |/ // __// _ `// _ \/ _ `// // -_)/ __/
#/___//_//_/\__//_//_/  |__/|__//_/   \_,_//_//_/\_, //_/ \__//_/   
#                                               /___/               
#   ___ _                        ___         _ _         _           
#  / __| |_  __ _ _ _ __ _ ___  |_ _|_ _  __| (_)__ __ _| |_ ___ _ _ 
# | (__| ' \/ _` | '_/ _` / -_)  | || ' \/ _` | / _/ _` |  _/ _ \ '_|
#  \___|_||_\__,_|_| \__, \___| |___|_||_\__,_|_\__\__,_|\__\___/_|  
#                    |___/                                           
#
# Script author: gadominas@gmail.com
# 
#   Native battery charge indicator tells you a little lie about fully
# charged battery. When it hits 100% in your taskbar in fact your battery 
# in fact is charged in 94-96% of full charge.
#
# ChargeIndicator script calculates battery charge level based on battery max capacity
# and current battery capacity values. For example standart OSX battery indicator shows
# you 100% when your battery current capacity is 8130 mAh where max capacity for example
# is 8233 mAh which leads to ~98.8% of full battery charge (8130*100/8233).
#
# Using this script you can monitor your battery charge level with more precise calculation
# and extend your battery lifespan by unplugging your AC power at the right time. 
# Basically it takes plus 10-15minutes to fully charged battery since OSX indicated 100%
# of fully charge.
# Default configuration is 97% percentage for a limit for fully charged battery.
#
#$$${ Battery charge indicator based on MAX and CURRENT battery amperage. }                                                                                                             

## configuration section
#@@@{Percentage for fully charged battery}
fullyCharged=96

isACPower() {
	if [[ $(pmset -g ps | head -1) =~ "AC Power" ]]; 
		then
  			return 1
	  	else
			return 0
	fi
}

drawBatteteryInfo() {
	isACPower
	acPower=$(printf $?)
	 	
	batPerc=$(/usr/sbin/ioreg -l | \
	 /usr/bin/awk '$3~/Capacity/{c[$3]=$5}END{OFMT="%.2f%";max=c["\"MaxCapacity\""];print(max>0?100*c["\"CurrentCapacity\""]/max:"?")}')

	if [ ${batPerc%.*} -gt $fullyCharged ] && [ $acPower -eq "1" ];
	 then
		printf "✅"
	 else
		printf "❗%s%c" $batPerc '%'
	fi
}

run() {
	drawBatteteryInfo
}

run