Skip to content

Instantly share code, notes, and snippets.

@robzr
Created February 19, 2024 06:40
Show Gist options
  • Save robzr/2abf9c7e7f576d8af00d90b671489b48 to your computer and use it in GitHub Desktop.
Save robzr/2abf9c7e7f576d8af00d90b671489b48 to your computer and use it in GitHub Desktop.
macOS Command Line to print power consumption, adapter wattage/profiles and power consumers
ioreg -w 0 -n AppleSmartBattery | \
jq -Rr '
select(
test("(AdapterDetails|AppleRawAdapterDetails|PowerOutDetails|PowerTelemetryData)")
)
| gsub("="; ":")
| gsub("\\("; "[")
| gsub("\\)"; "]")
| gsub(":(?<value>[^ ][A-Za-z]+)"; ": \"\(.value)\"")
| sub("^[^\"]*"; "")
| "{\(.)}"
| fromjson
' | \
jq -s \
'
add
| {
Adapter: {
Watts: .AdapterDetails.Watts,
Profiles: (
.AdapterDetails.UsbHvcMenu
| map("\(.MaxVoltage / 1000)v @ \(.MaxCurrent / 1000)a")
)
},
Consuming: (
.PowerTelemetryData
| "\(.SystemPowerIn / 1000)w \(.SystemVoltageIn / 1000)v @ \(.SystemCurrentIn / 1000)a"
),
Providing: (
.PowerOutDetails
| map("Port \(.PortIndex): \(.Watts / 1000)w \(.AdapterVoltage / 1000)v @ \(.Current / 1000)a")
)
}
'
@robzr
Copy link
Author

robzr commented Feb 19, 2024

Example output:

{
  "Adapter": {
    "Watts": 94,
    "Profiles": [
      "5v @ 3a",
      "9v @ 3a",
      "15v @ 3a",
      "20v @ 4.7a"
    ]
  },
  "Consuming": "12.685w 20.474v @ 0.619a",
  "Providing": [
    "Port 2: 7.078w 5.202v @ 1.36a"
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment