Skip to content

Instantly share code, notes, and snippets.

@lucaspiller
Forked from jehiah/activity_snapshot.sh
Last active December 10, 2015 18:58
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lucaspiller/4478297 to your computer and use it in GitHub Desktop.
Save lucaspiller/4478297 to your computer and use it in GitHub Desktop.
#!/bin/zsh
# computer activity data collection for http://jehiah.cz/one-two/
# Originally by Jehiah Czebotar. This verison by Luca Spiller.
FILE="$HOME/Dropbox/activity_log/`hostname`-`date +%Y%m%d`.log"
function log_activity()
{
local TIME=`date "+%Y-%m-%dT%H:%M:%S%z"`
local IDLE=$((`/usr/sbin/ioreg -c IOHIDSystem | sed -e '/HIDIdleTime/!{ d' -e 't' -e '}' -e 's/.* = //g' -e 'q'` / 1000000000 ))
local ACTIVE_PROGRAM=$(/usr/bin/osascript -e 'tell application "System Events"' -e 'set frontApp to name of first application process whose frontmost is true' -e 'end tell')
local WEBSITE=$(/usr/bin/osascript -e 'tell application "Google Chrome"' -e 'if not exists (window 1) then' -e 'set urlString to ""' -e 'else' -e 'set urlString to URL of active tab of window 1' -e 'end if' -e 'end tell')
echo "$TIME\t$IDLE\t$ACTIVE_PROGRAM\t$WEBSITE" >> $FILE
}
log_activity
sleep 30
log_activity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment