Created
October 21, 2012 20:27
-
-
Save pachacamac/3928399 to your computer and use it in GitHub Desktop.
Log what programs you're using
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
#!/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