-
-
Save ksexton/6571299 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require 'rubygems' | |
require 'bundler/setup' | |
require 'appscript' | |
# http://stackoverflow.com/questions/480866/get-the-title-of-the-current-active-window-document-in-mac-os-x | |
while true | |
frontmost = Appscript.app('System Events').application_processes.get.select{ |a| a.frontmost.get }.first | |
if frontmost | |
puts frontmost.name.get | |
if frontmost.windows.count > 0 | |
window = frontmost.windows.first | |
puts window.name.get | |
# Chrome Active Tab | |
# http://stackoverflow.com/questions/2483033/get-the-url-of-the-frontmost-tab-from-chrome-on-os-x | |
if frontmost.name.get == 'Google Chrome' | |
tab = Appscript.app('Google Chrome').windows[0].active_tab | |
puts tab.URL.get | |
puts tab.name.get | |
end | |
end | |
end | |
sleep 0.25 | |
end | |
# System Idle Time | |
# http://www.dssw.co.uk/sleepcentre/threads/system_idle_time_how_to_retrieve.html | |
# ioreg -c IOHIDSystem | perl -ane 'if (/Idle/) {$idle=(pop @F)/1000000000; print $idle,"\n"; last}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment