Hacker News new | ask | show | jobs
by spion 2674 days ago
I have this in a cron:

  * 08-23 * * * ~/.local/bin/with-i3 '~/.local/bin/record-active-window'
this is record-active-window:

  # set LOGFILE to whatever place you want to record things.

  echo "DATE = $(date +%s 2>&1)" >> $LOGFILE
  echo "IDLE = $(xprintidle)" >> $LOGFILE
  xprop -id $(xprop -root  _NET_ACTIVE_WINDOW | sed 's/.*# //') WM_CLASS WM_NAME 2>&1 >> $LOGFILE
this is with-i3

  #!/bin/bash

  source <(cat /proc/`ps -e | grep ' i3$' | awk '{print $1}'`/environ  | sed -r -e 's/([^\x00]*)\x00/export \1\n/g')
  bash -c "$*"
I was too lazy to figure out what env vars were missing from the cron (probably dbus socket) so i copied them all from the i3 process above

That plus the habit to lock the screen while I'm away from it works fairly reliable.

edit: you also have the idle time in case you want to ignore result where you've been idle for way too long (forgot to lock screen)

edit2: a sample log entry (idle is in miliseconds, date is unix timestamp in seconds)

  DATE = 1550608681
  IDLE = 2456
  WM_CLASS(STRING) = "google-chrome", "Google-chrome"
  WM_NAME(UTF8_STRING) = "Edit | Hacker News - Google Chrome"
If only Slack changed the window title when I change chats, I could also track how much time I spend talking where :) The web version does it though, so I might stop using the electron app...
2 comments

Have you come across arbtt? It's a script that pretty much does exactly the same thing, but comes with a few extras for categorization and analysis.
I don't like arbtt because it has an undocumented binary log format making it unnecessarily difficult to build tools on top of it. Its documentation in general is also poorly written.

This is not perfect either, but its just a little extra work to convert it to JSON and put it in elasticsearch to use kibana on it.

I did something similar and found it to be useless for how I work. I even wrote a second tool in Rust that uses the WINAPI (throwback to 1998 when I last used it). Sure, numbers might be 50% correct, but maybe they're not.

Say I'm supposed to write some code, so the IDE should be the front window. But I get carried away trying to test an edge case, so I spend 4h in a shell doing stuff that's 100% related, but not in the IDE. Not really a contrived example. Or spending 3h in a browser researching something and reading docs and forum posts about $software when I was supposed to write a one liner fix.

TLDR: Didn't work, gave up with it.

You can't just automatically use the results - at the end I group them by window title and look at things that are > 5m

Not perfect but decent.

Of course I did some post-processing, didn't really help - for me - as I wrote.

But just take the category "browser usage" as an example.

Semi-relatedly, one reason I hate web apps for "persistent" things that should be standalone, e.g. stuff like Slack or E-Mail. Not only does it not fit my mental model with alt-tabbing, it also lumps this uselessly together like "GUI usage vs CLI", so broad is "browser".

Window titles are recorded by this script. I wonder if you noticed this? You could have pretty decent filters with those, e.g. you can get a result for "time spent reading comments and writing on hackernews". If I use slack in the browser, i can even get the time i spent talking to different people / channels.