]>
code.delx.au - monosys/blob - scripts/osx_battery
b1fcffbbfc061d05a42d4f1ec4dcc2d169a3e476
8 # Run ioreg to get the battery status line
9 classes
= ["AppleSmartBattery", "IOBatteryInfo"]
10 cmd
= ["ioreg", "-w0", "-r", "-c"]
13 p
= subprocess
.Popen(args
=cmd
+ [klass
], stdout
=subprocess
.PIPE
)
14 iterables
.append(p
.stdout
)
17 for line
in itertools
.chain(*iterables
):
18 if line
.startswith("+"):
21 if line
.find("=") >= 0:
22 line
= line
.replace("Yes", "True").replace("No", "False")
23 line
= line
.replace("=", ":")
24 if line
.find("<") >= 0:
25 line
= line
.replace("<", "'<").replace(">", ">'")
28 exec "data = " + "\n".join(lines
)
44 if data
.has_key(field
):
45 print (field
+":").ljust(3+max(map(len, fields
))),