-
Notifications
You must be signed in to change notification settings - Fork 2
/
zentrackerd
executable file
·59 lines (53 loc) · 1.19 KB
/
zentrackerd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
: ${ZENDIR:="$HOME/.zentracker"}
function init()
{
if [ ! -d "$ZENDIR" ]; then
echo "Creating directory $DATA_DIR..."
mkdir -p "$ZENDIR"
fi
}
function get_current_activity()
{
local v=$(cat <<EOF
tell application "System Events"
set frontApp to the name of the first application process whose frontmost is true
set appID to id of application process frontApp
try
tell (process id appID) to set frontDocument to the name of the front document
on error
try
tell (process id appID) to set frontDocument to the name of the front window
on error
set frontDocument to ""
end try
end try
end tell
get frontApp & "\n" & frontDocument
EOF)
/usr/bin/osascript -e "$v"
}
function log_activity()
{
file="$ZENDIR/"`date "+%Y-%m-%d"`
if [ ! -f "$file" ]; then
touch "$file"
fi
# read from applescript
read frontApp
read frontDocument
now=`date "+%H:%M"`
echo -e "$now""\t""$frontApp""\t""$frontDocument" >> "$file"
}
function sleep_till_next_min()
{
local v=`date '+%S'`
((sec=60-10#"$v"))
echo "$sec"
}
echo "ZenTracker is running..."
init
while true; do
get_current_activity | log_activity
sleep $(sleep_till_next_min)
done