Last active
February 12, 2025 08:33
-
-
Save evokateur/afb829732178f8d0ec37db56b868c69f to your computer and use it in GitHub Desktop.
Check hardware battery pct in macOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
current_capacity=$(ioreg -l | grep -o '"CurrentCapacity" = [0-9]*' | awk '{print $3}') | |
max_capacity=$(ioreg -l | grep -o '"MaxCapacity" = [0-9]*' | awk '{print $3}') | |
design_capacity=$(ioreg -l | grep -o '"DesignCapacity" = [0-9]*' | awk '{print $3}') | |
if [[ -n "$current_capacity" && -n "$max_capacity" && "$max_capacity" -ne 0 && -n "$design_capacity" && "$design_capacity" -ne 0 ]] | |
then | |
percentage=$(echo "scale=2; ($current_capacity / $max_capacity) * 100" | bc) | |
echo "Battery charge: $percentage%" | |
percentage=$(echo "scale=2; ($max_capacity / $design_capacity) * 100" | bc) | |
echo "Battery health: $percentage%" | |
else | |
echo "Error: Could not extract battery data." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://apphousekitchen.com/feature-explanation-hardware-battery-percentage/