Created
December 8, 2014 02:04
-
-
Save stanaka/71340942513c03e19bd0 to your computer and use it in GitHub Desktop.
This file contains 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 ruby | |
$ioreg = `ioreg -r -n AppleSmartBattery` | |
$now = Time.now | |
def asb(item) | |
ret = $ioreg.match(/(#{item})[\"= ]+(\d+)$/) | |
ret[2].to_i | |
end | |
puts "Battery.capacity.MaxCapacity\t#{asb("MaxCapacity")}\t#{$now.to_i}" | |
puts "Battery.capacity.CurrentCapacity\t#{asb("CurrentCapacity")}\t#{$now.to_i}" | |
puts "Battery.cycle.CycleCount\t#{asb("CycleCount")}\t#{$now.to_i}" | |
puts "Battery.temperature.Temperature\t#{asb("Temperature").to_f / 100}\t#{$now.to_i}" | |
timeremain = asb("TimeRemaining") | |
puts "Battery.timeremaining.TimeRemaining\t#{timeremain > 2000 ? 0 : timeremain}\t#{$now.to_i}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment