Created
August 21, 2011 07:29
-
-
Save joneskoo/1160290 to your computer and use it in GitHub Desktop.
Read battery information from System Profiler (OS X)
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
#!/usr/bin/env python3 | |
from tempfile import NamedTemporaryFile | |
from subprocess import call | |
import plistlib | |
with NamedTemporaryFile() as f: | |
call(['system_profiler', '-xml', 'SPPowerDataType'], stdout=f) | |
f.seek(0) | |
p = plistlib.readPlist(f) | |
d = p[0]['_items'][0] | |
voltage = d['sppower_current_voltage'] | |
amperage = d['sppower_current_amperage'] | |
chargeinfo = d['sppower_battery_charge_info'] | |
maxcap = chargeinfo['sppower_battery_max_capacity'] | |
is_charging = chargeinfo['sppower_battery_is_charging'] | |
capacity = chargeinfo['sppower_battery_current_capacity'] | |
print("%d mV %d mA (full: %d mAh)" % (voltage, amperage, maxcap)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment