Posted on 02-10-2021 03:27 AM
Is there a way to pull the battery health information? cycles and max charge info.
Posted on 02-10-2021 03:51 AM
@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.
Posted on 09-29-2021 10:18 AM
Thank you.
11-07-2021 10:40 AM - edited 11-07-2021 11:50 AM
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
Posted on 02-10-2021 03:52 AM
Thanks!!
Posted on 02-10-2021 11:17 AM
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/
Posted on 02-10-2021 10:18 PM
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.
Posted on 02-11-2021 05:44 AM
@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.
Posted on 02-22-2021 08:10 AM
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.
Posted on 11-08-2021 03:11 AM
@brayg thanks for the update but I'm not getting any results from it ! I have M1 Mac that is running Monterey
Posted on 11-08-2021 08:49 AM
@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.
Posted on 11-08-2021 11:44 PM
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!
Posted on 03-23-2022 05:01 AM
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.
Posted on 03-23-2022 12:49 PM
echo "<result>$(ioreg -r -c "AppleSmartBattery" | grep -w "MaxCapacity" | sed -e 's/[" MaxCcpity=]//g')</result>"
Is this a typo MaxCcpity ?
Posted on 03-23-2022 12:56 PM
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.
Posted on 03-23-2022 01:08 PM
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)?
Posted on 05-12-2022 12:18 AM
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
Posted on 03-27-2022 09:30 AM
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>"
Posted on 10-28-2022 06:35 AM
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
Posted on 03-22-2023 09:08 AM
Works nicely, thanks.
Posted on 01-04-2024 04:19 PM
Thank you.