Module: IsMacIdle

Defined in:
lib/is_mac_idle.rb,
lib/is_mac_idle/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.brightnessObject



10
11
12
# File 'lib/is_mac_idle.rb', line 10

def brightness
  `ioreg -c AppleBacklightDisplay`.scan(/"brightness"[^}]+=(\d+)}/)[0][0].to_f
end

.idle_timeObject



6
7
8
# 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) ⇒ Object



14
15
16
17
18
19
20
21
22
# 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