Print current Mac wattage (with accuracy up to minute)
This file contains 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
#!/usr/bin/env bash | |
set -euo pipefail | |
function extract_float_field() { | |
field=$1 | |
ioreg -rw0 -c AppleSmartBattery | | |
grep BatteryData | | |
sed -E "s/.*\"$field\"=([0-9]+).*/\1/" | | |
xargs -I % lldb --batch -o "print/f %" | # Convert IEEE-754 float | |
grep -o '$0 = [0-9.]*' | | |
sed 's/.*= //' | |
} | |
printf -- 'Charging (watt): ' | |
extract_float_field AdapterPower | |
printf -- 'Consumption (watt): ' | |
extract_float_field SystemPower |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment