MacBook battery health information?

mwu1876
Contributor

Is there a way to pull the battery health information? cycles and max charge info.

20 REPLIES 20

greatkemo
Contributor II

@mwu1876 Yes! If you are using jamf pro, Go to Settings > Computer Management > Extended Attributes > New From Template. And you should see some battery templates listed under "System Information". I found that some of them need some slight updating to work better with newer versions of macOS, obviously goes without saying, test test test.

If you are looking for something to report on the condition of the battery, then you can try this out.

#!/bin/bash

echo "<result>$(system_profiler SPPowerDataType | grep "Condition:" | sed 's/.*Condition: //')</result>"

exit 0

Hope this was helpful.

Thank you.

brayg
New Contributor III

This was extremely helpful. The default "Battery Capacity" option is not working on M1 Macs so I adjusted your script slightly to report maximum battery capacity for these new Macs. Have only tested on M1 + Monterey so far.
Update: Only works on M1 Macs

 

 

#!/bin/sh

#Show maximum capacity of battery compared to when it was new (100%)

echo "<result>$(system_profiler SPPowerDataType | grep "Maximum Capacity:" | sed 's/.*Maximum Capacity: //')</result>"

exit 0

 

 

 

mwu1876
Contributor

Thanks!!

mpenrod
New Contributor III

What he said but check out this guy for more: https://joelsenders.wordpress.com/2019/03/28/determining-battery-health-via-extension-attributes-in-jamf/

greatkemo
Contributor II

Just take into consideration that the article @mpenrod shared, has multiple conditions the battery can be in, according to Apple from Catalina, and later those conditions are now only 2:

Normal: The battery is functioning normally. Service recommended: The battery is performing normally, but its ability to hold a charge is less than when it was new. You may want to consider replacing the battery.

source: macOS User Guide

Hope this helps.

mwu1876
Contributor

@greatkemo Ok thanks! Yeah, I was originally looking for a battery health % but it sounds like when it says service recommended now I should just assume that it's low enough that it should get replaced.

user-JMaEaLtHtT
New Contributor

Hold the Option key and click the Apple  menu. Choose System Information. Under the Hardware section of the System Information window, select Power. The current cycle count is listed under the Battery Information section.
Your MacBook constantly monitors the health of its battery. To view the current status: Hold down the Alt/Option key. Click the battery charge icon at the top right of the desktop near the clock.

MacJunior
Contributor III

 

 @brayg thanks for the update but I'm not getting any results from it ! I have M1 Mac that is running Monterey 

 

brayg
New Contributor III

@MacJunior you could try running this by itself in Terminal locally:

echo "<result>$(system_profiler SPPowerDataType | grep "Maximum Capacity:" | sed 's/.*Maximum Capacity: //')</result>"

If it returns "<result>100%</result>" (or whatever the percent is) the script should be working. The exit 0 could be removed if using the script through Jamf. Right now we have all Big Sur/Monterey M1 models reporting back using that same script. It could definitely use some logic to account for both Intel and M1 though. 

weird ! I tried it before via Terminal on my M1 Mac and I didn't get any result like this : 

<result></result>

Just tried it on another M1 testing machine and it showed a true maximum capacity value!

AVmcclint
Honored Contributor

I'm trying to use this info to build a single EA that will work for both intel and Apple silicon, but my scripting skills aren't quite there yet.

#!/bin/bash

#determine CPU
chip=`system_profiler SPHardwareDataType | grep "Chip:" | cut -d ' ' -f 9`
if [[ "$chip" =~ "M" ]]; then
# new EA that works on Apple Silicon
	echo "<result>$(system_profiler SPPowerDataType | grep "Maximum Capacity:" | sed 's/.*Maximum Capacity: //')</result>"
else	
# old EA that works for intel	
echo "<result>$(ioreg -r -c "AppleSmartBattery" | grep -w "MaxCapacity" | sed -e 's/[" MaxCcpity=]//g')</result>"

fi

When I run this as a script locally on either hardware, it works fine. But when I run it as an EA, the intel portion results in nothing while the Apple Silicon portion works fine. I can't figure out what I'm doing wrong.

devlinford
New Contributor III
echo "<result>$(ioreg -r -c "AppleSmartBattery" | grep -w "MaxCapacity" | sed -e 's/[" MaxCcpity=]//g')</result>"

Is this a typo MaxCcpity ?

AVmcclint
Honored Contributor

I'm not really sure because that was the original EA we were using when we didn't have any M1 Macs. It worked then and works now as long as it is run in a script. I'm not above replacing that whole command if there's another that will work as an EA.

devlinford
New Contributor III

Ya, I guess it IS legit syntax

When I run this:

ioreg -r -c "AppleSmartBattery" | grep -w "MaxCapacity" | sed -e 's/[" MaxCcpity=]//g'

Locally in Terminal, I get the following output on an Intel Mac: 4549

Is that what you are expecting or a percentage (between 1-100)?

have you tried using system profiler for the intel

#!/bin/bash

#determine CPU
chip=`system_profiler SPHardwareDataType | grep "Chip:" | cut -d ' ' -f 9`
if [[ "$chip" =~ "M" ]]; then
# new EA that works on Apple Silicon
	echo "<result>$(system_profiler SPPowerDataType | grep "Maximum Capacity:" | sed 's/.*Maximum Capacity: //')</result>"
else	
# old EA that works for intel	
echo "<result>$(system_profiler SPPowerDataType | grep "Full Charge Capacity" | sed 's/.*Full Charge Capacity (mAh): //')</result>"

fi

brayg
New Contributor III

FWIW this is on Jamf's radar. I reached out to support to report that their default battery percentage (built into Jamf) isn't reporting Apple Silicon Mac battery health % correctly. I received the response below:

This is a current product issue, PI103759, and I have tied this case to that product issue.

There is a workaround, and that workaround is to create an extension attribute with the following info:

echo "<result>$(system_profiler SPPowerDataType | sed -n -e 's/^.*State of Charge (%): //p')"%"</result>"

Bigmike
New Contributor II

I just combined the 2 so if it's an Intel Mac it will just read the battery status and M1 with having the status and capacity.

arch=$(/usr/bin/arch)

if [ "$arch" == "arm64" ]; then

capacity=$(system_profiler SPPowerDataType | grep "Maximum Capacity:" | sed 's/.*Maximum Capacity: //')
echo "<result>$(system_profiler SPPowerDataType | grep "Condition:" | sed 's/.*Condition: //') with $capacity capacity</result>"

elif [ "$arch" == "i386" ]; then

echo "<result>$(system_profiler SPPowerDataType | grep "Condition:" | sed 's/.*Condition: //')</result>"

else

echo "<result>Unknown Architecture</result>"

fi

Bretterson
New Contributor III

Works nicely, thanks.

Bigmike
New Contributor II

Thank you.