#!/usr/bin/env ruby -wKU res = Array.new res = %x(/usr/sbin/ioreg -p IODeviceTree -n "battery" -w 0).grep(/Battery/)[0].match(/\{(.*)\}/)[1].split(',') stats = Hash.new res.each do |d| key, val = d.split("=") key.downcase!.delete!(" ") if key =~ /\"(.*)\"/ key = $1 end stats[:"#{key}"] = val end puts puts "-------------------------------" puts " Battery Stats" puts "-------------------------------" puts stats.each { |k, v| puts "#{k} => #{v}" } percentOfOriginal = (stats[:capacity].to_f / stats[:absolutemaxcapacity].to_f) * 100 puts "Battery capacity is currently #{sprintf("%.2f", percentOfOriginal)}% of original."
Never been to CodeSnippets before?
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)
battstatt.rb, an OS X Leopard battery stats grabber (See related posts)
You need to create an account or log in to post comments to this site.
Related Posts
» Rails MySQL Session Sweeper in ruby rails osx tiger launchd lingon
» Install Rails/lighttpd with ... in lighttpd ruby rails osx tiger
» Install postgres gem on Mac ... in ruby osx gem postgres postgresql
» Using this function you will... in apache php mysql find ruby rails time date perl regex shell http osx mac css python google html bash error windows sql activerecord javascript java rubyonrails unix linux database c text csharp XSLT image string xml file array web url math mongrel_cluster hash convert dscl C++ sips series60 rexml REBOL jonas jsfromhell raoni sinatra rscript
» Statement Emulation in apache php mysql find ruby rails time date perl regex shell http osx mac css python google html bash error windows sql activerecord javascript java rubyonrails unix linux database c text csharp XSLT image string xml file array web url math mongrel_cluster hash convert dscl C++ sips series60 rexml REBOL jonas jsfromhell raoni sinatra rscript
» Fill data into an XML templa... in apache php mysql find ruby rails time date perl regex shell http osx mac css python google html bash error windows sql activerecord javascript java rubyonrails unix linux database c text csharp XSLT image string xml file array web url math mongrel_cluster hash convert dscl C++ sips series60 rexml REBOL jonas jsfromhell raoni sinatra rscript
Snippets (source code soon to be available) developed by Peter Cooper and powered by Ruby On Rails