Created
May 16, 2009 17:31
-
-
Save relrod/112737 to your computer and use it in GitHub Desktop.
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/ruby | |
batt_stats = %x[ioreg -n battery -w 0 | grep BatteryInfo] | |
stats_info = batt_stats.match(/"Capacity"=(.*),"Amperage"=(.*),"Cycle Count"=(.*),"Current"=(.*),"Voltage"=(.*),"Flags"=(.*),"AbsoluteMaxCapacity"=(.*)\}/i) | |
stats_info = stats_info.to_a | |
capacity = stats_info[1].to_i | |
amperage = stats_info[2].to_i | |
cycle_count = stats_info[3].to_i | |
current = stats_info[4].to_i | |
voltage = stats_info[5].to_i | |
flags = stats_info[6].to_i | |
absolutemaxcapacity = stats_info[7].to_i | |
battery_charge = current/capacity | |
battery_charge = battery_charge * 100 | |
puts battery_charge | |
puts capacity | |
puts current |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment