karpathy / ulogme

Automatically collect and visualize usage statistics in Ubuntu/OSX environments.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nothing else than "Locked Screen"

matthieu-vergne opened this issue · comments

Hi,

I have just tried your stuff on my machine (Kubuntu 14.04 LTS) but while the total key frequencies update well in the bottom of the overview, the only window listed is "Locked Screen" with really small values (32 keys). On the single-day view there is also only this window with a small value (1m4s). Even if I re-execute manually the refreshing in the console and then refresh the interface, only the key frequencies change (by the way I did not need to sudo anything).

Additionally, locking my screen during a while and unlocking does not change the time spent, and executing manually the refresh in command line gives me this error:

a log file has changed, so will update render/events_1434085200.json
logs/notes_1434085200.txt probably does not exist, setting empty events list.
error was:
[Errno 2] No such file or directory: 'logs/notes_1434085200.txt'
wrote render/events_1434085200.json
wrote render/export_list.json

Any suggestion/fix?

I don't quite know how to fix the "always locked" error, but I do know that the "notes_...txt" error isn't actually an error unless you took any notes in that time, which would imply the expectation that the file should exist. The file doesn't get created if you don't make any notes.

I can lead you on a path to finding a solution: look at the file logactivewin.sh, where the program detects whether your screen is locked or not by looking at various environment variables. Assuming you're using KDE, running qdbus org.kde.screensaver /ScreenSaver org.freedesktop.ScreenSaver.GetActive in a Terminal should return nothing (empty string) if you execute it while unlocked, and running echo $XDG_SESSION_DESKTOP should return "KDE". I can't really test for myself because I don't have KDE.

If you can't solve it yourself, then replacing lines 20 to 36 in that file with islocked=false would disable the check. Your file should then look like this if you are using the main git branch:

#!/bin/bash

LANG=en_US.utf8

# logs the active window titles over time. Logs are written 
# in logs/windowX.txt, where X is unix timestamp of 7am of the
# recording day. The logs are written if a window change event occurs
# (with 2 second frequency check time), or every 10 minutes if 
# no changes occur.

waittime="2" # number of seconds between executions of loop
maxtime="600" # if last write happened more than this many seconds ago, write even if no window title changed
#------------------------------

mkdir -p logs
last_write="0"
lasttitle=""
while true
do
    islocked=false

    if [ $islocked = true ]; then
        curtitle="__LOCKEDSCREEN"
    else 
        id=$(xdotool getactivewindow)
        curtitle=$(wmctrl -lpG | while read -a a; do w=${a[0]}; if (($((16#${w:2}))==id)) ; then echo "${a[@]:8}"; break; fi; done)
    fi

    perform_write=false

    # if window title changed, perform write
    if [[ "$lasttitle" != "$curtitle" ]]; then
        perform_write=true
    fi

    T="$(date +%s)"

    # if more than some time has elapsed, do a write anyway
    #elapsed_seconds=$(expr $T - $last_write)
    #if [ $elapsed_seconds -ge $maxtime ]; then
    #   perform_write=true
    #fi

    # log window switch if appropriate
    if [ "$perform_write" = true ]; then 
        # number of seconds elapsed since Jan 1, 1970 0:00 UTC
        logfile="logs/window_$(python rewind7am.py).txt"
        echo "$T $curtitle" >> $logfile
        echo "logged window title: $(date) $curtitle into $logfile"
        last_write=$T
    fi

    lasttitle="$curtitle" # swap
    sleep "$waittime" # sleep
done

Well, after one year, a switch to Ubuntu 16.04, and no reuse of this project, I have to say that I don't even remember/care about it. {'^_^}

So let's close it.