-
Notifications
You must be signed in to change notification settings - Fork 10
/
pyioreg-objc.py
executable file
·37 lines (26 loc) · 1.11 KB
/
pyioreg-objc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/python
#ref https://gist.github.com/pudquick/c7dd1262bd81a32663f0
import objc
from Foundation import NSBundle
IOKit_bundle = NSBundle.bundleWithIdentifier_('com.apple.framework.IOKit')
functions = [("IOServiceGetMatchingService", b"II@"),
("IOServiceMatching", b"@*"),
("IORegistryEntryCreateCFProperty", b"@I@@I"),
]
objc.loadBundleFunctions(IOKit_bundle, globals(), functions)
def io_key(keyname):
return IORegistryEntryCreateCFProperty(IOServiceGetMatchingService(0, IOServiceMatching("IOPlatformExpertDevice")), keyname, None, 0)
def battery_info(keyname):
return IORegistryEntryCreateCFProperty(IOServiceGetMatchingService(0, IOServiceMatching("AppleSmartBattery")), keyname, None, 0)
def get_hardware_uuid():
return io_key("IOPlatformUUID")
def get_hardware_serial():
return io_key("IOPlatformSerialNumber")
def get_battery_charge():
return battery_info("FullyCharged")
def get_battery_capacity():
return battery_info("CurrentCapacity")
print get_hardware_uuid()
print get_hardware_serial()
print get_battery_charge()
print get_battery_capacity()