Skip to content

Instantly share code, notes, and snippets.

@stanaka
Created December 8, 2014 02:04
Show Gist options
  • Save stanaka/71340942513c03e19bd0 to your computer and use it in GitHub Desktop.
Save stanaka/71340942513c03e19bd0 to your computer and use it in GitHub Desktop.
#! /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