Skip to content

Instantly share code, notes, and snippets.

@Rogach
Created May 18, 2012 08:11
Show Gist options
  • Save Rogach/2723911 to your computer and use it in GitHub Desktop.
Save Rogach/2723911 to your computer and use it in GitHub Desktop.
Activity tracker
#!/usr/bin/scala
!#
val activities = Seq(
("blogging", "chrome", "^Blogger".r),
("games", "chrome", "Game".r),
("guake", "python", "^Guake!$".r)
)
io.Source.fromFile(args(0)).getLines.toList // read the file
.map(_.span(' '!=)).map(t => (t._1, t._2.trim.drop(1).reverse.drop(1).reverse)) // extract process-title pairs
// convert those specific activities
.map { case (prog, title) =>
activities.find { case (act, exec, regex) => prog == exec && regex.findFirstIn(title).isDefined }
.map(_._1).getOrElse(prog)
}
.groupBy(a=>a).toList
.map(t => (t._1, t._2.size))
.sortWith(_._2 > _._2)
.foreach { p => println("%4d %s" format(p._2, p._1)) }
#!/bin/bash
# since we are launching from cron, we need to tell it which display to use
export DISPLAY=:0.0
# and also we want to stop logging when screensaver is active
if [[ $(gnome-screensaver-command -q | head -1) =~ "inactive" ]]
then
windowid=$(xdotool getwindowfocus)
windowproc=$(ps -e | grep $(xdotool getwindowpid $windowid) | grep -v grep | awk '{print $4}')
windowtitle=$(xwininfo -root -children | grep $(printf '%x\n' $windowid) | grep -oEi '"[^"]+"' | head -1)
echo $windowproc $windowtitle >> ~/log/activity/`date +%y-%m-%d`.log
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment