module IsMacIdle

Constants

VERSION

Public Instance Methods

brightness() click to toggle source
# File lib/is_mac_idle.rb, line 10
def brightness
  `ioreg -c AppleBacklightDisplay`.scan(/"brightness"[^}]+=(\d+)}/)[0][0].to_f
end
idle_time() click to toggle source
# File lib/is_mac_idle.rb, line 6
def idle_time
  `ioreg -c IOHIDSystem`.scan(/HIDIdleTime" = (\d+)/)[0][0].to_f / 1000_000_000
end
net_traffic(sec = 1) click to toggle source
# File lib/is_mac_idle.rb, line 14
def net_traffic(sec = 1)
  Open3.popen3("netstat -i -w #{sec}") do |i, o, e, th|
    o.gets
    o.gets
    a = o.gets.split.map(&:to_i)
    th.kill
    {in: a[2], out: a[5]}
  end
end