Automatic alerts of time spent on computer
June 1, 2009 8:57 AM   Subscribe

Does anyone know a way to create alerts in Ubuntu every x number of minutes of how long spent on the computer that day?

I think an alert system of how long spent on the computer that day would really help with my time management. I don't know if an application or script would be what I am looking for. I tried the hamster time tracking panel app, but that is less ideal, because I can forget to get it to start tracking.
posted by LaszloKv to Computers & Internet (8 answers total) 1 user marked this as a favorite
 
I'm not sure how to create an alert, but running "uptime" in Terminal shows you how long your computer's been running from the last startup. That would be my starting point at least.
posted by aheckler at 9:00 AM on June 1, 2009


Also the command "w" in a terminal will show you what time you logged in.
posted by Luddite at 9:03 AM on June 1, 2009


As a DIY coding project, it's not too hard...

It's easy enough to write a program that runs in the background and pops up an alert periodically. The harder question is how to determine "how long spent on the computer" --- uptime just tells you how long the computer has been on.

xscreensaver has idle information, available to through the libxss API. More convenient would be something like this Python xss module, which you could use to poll the screensaver and record idle status. From that you could put together a pretty good estimate.
posted by qxntpqbbbqxl at 9:24 AM on June 1, 2009


Try zenity for the popup. Something like "zenity --info --text='You have been on the computer for n minutes today.'"

I like the idea of using who/w for time tracking. How about "w | awk '{print $6}'" to get your recent usage? If there are multiple users you might have to grep them out. Call this once a minute and grep for two digits followed by an s (indicating that you've used the machine that many seconds ago). If you do have results in that many seconds, add one to your minute counter. If not, assume you're idle and do nothing. Then open zenity reading your minute counter as often as needed.

Note that this is the quick and dirty method, and libxss would be better.
posted by valadil at 10:28 AM on June 1, 2009


You could also grep the process list (ps) for programs that you use while working, have that cron'd every 15 minutes or so, and update a tally of 15-min blocks and the equivalent hours (n/4) to a date-based filename.
posted by cowbellemoo at 11:36 AM on June 1, 2009


quick 'n' dirty (slight) expansions on valadil's idea:


zenity --info --text="$(w -h)"
would pop up the relevant w output

to pop up once every 15 minutes, maybe this?

while true; do zenity --info --text="$(w -h)"; sleep 15m; done

posted by namewithoutwords at 11:42 AM on June 1, 2009


I use this script to pop up a reminder every 15 minutes on my computer:

#!/bin/bash

#kill any previous boxes
kill $(ps aux | grep "Right now:" | grep -v "grep" | awk '{print $2}')

#now start a new one
zenity --question --title "Alert" --text "Right now: Is this really what you want to be doing?"
save it somewhere, then edit your crontab (using 'crontab -e') to add the script:
0,15,30,45 * * * * export DISPLAY=:0 && bash /path/to/yourscript.sh 2> /dev/null

It wouldn't be too hard to modify this script so that you write out the time to a file, then every 15 minutes, read that time, increment it, display the result, and write it back to the file.
posted by chrisamiller at 1:33 PM on June 1, 2009


You also might try the excellent time-tracker applet, which can add to your panel by right-clicking. (aka project hamster)
posted by chrisamiller at 1:34 PM on June 1, 2009


« Older Multiplayer Game for a kid and adult   |   Film of Ubu Roi Newer »
This thread is closed to new comments.