Skip to content

Instantly share code, notes, and snippets.

@pachacamac
Created October 21, 2012 20:27
Show Gist options
  • Save pachacamac/3928399 to your computer and use it in GitHub Desktop.
Save pachacamac/3928399 to your computer and use it in GitHub Desktop.
Log what programs you're using
#!/usr/bin/env ruby
DATA.flock(File::LOCK_EX | File::LOCK_NB) or abort "Already running."
Process.daemon(true)
def active_window_info
Hash[`xprop -id $(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)" | awk '{print $5}')`
.scan(/^WM_(NAME|CLASS).*? = "(.*?)"(, "|$)/)
.map{|e| e.first.downcase!; e[0..-2]}]
end
def log(*items)
File.write('./window.log', ([Time.now]+items).join("\t")<<"\n", :mode=>'a')
end
loop do
w = active_window_info
log(w['class'], w['name'])
sleep 1
end
__END__
DO NOT DELETE. USED FOR LOCKING
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment