Skip to content

Instantly share code, notes, and snippets.

@RustingSword
Last active January 25, 2024 19:07
Show Gist options
  • Save RustingSword/4368301 to your computer and use it in GitHub Desktop.
Save RustingSword/4368301 to your computer and use it in GitHub Desktop.
A simple time tracker implemented in AutoHotkey, modified from http://www.autohotkey.com/board/topic/37998-tiny-computer-usage-tracker/
; ticker - A Simple Time Tracker
; track your time usage on a daily basis
#InstallKeybdHook
#InstallMouseHook
Menu, Tray, Icon, %A_WinDir%\system32\shell32.dll, 44
Menu, Tray, Tip, ticker - A Simple Time Tracker`nPress right control to see details
SetWorkingDir, C:\Users\%A_UserName%\Documents
SetTimer, CheckTime, 60000 ; updates every 1 minute
CheckTime:
FormatTime, thedate, , dd-MM-yyyy
IniRead, ResearchTime, track.txt, %thedate%, research, 0
IniRead, ProgrammingTime, track.txt, %thedate%, programming, 0
IniRead, SurfingTime, track.txt, %thedate%, surfing, 0
IniRead, WastedTime, track.txt, %thedate%, waste, 0
IniRead, IdleTime, track.txt, %thedate%, idle, 0
If (A_TimeIdlePhysical < 600000) ; 10 minutes
{
If (WinActive("ahk_class classFoxitReader") or WinActive("ahk_class AcrobatSDIWindow"))
ResearchTime++
Else If (WinActive("ahk_class Vim") or WinActive("ahk_class Notepad2U"))
ProgrammingTime++
Else If (WinActive("ahk_class MozillaWindowClass") or WinActive("ahk_class Chrome_WidgetWin_1"))
SurfingTime++
Else
WastedTime++
}
Else
IdleTime++
TotalTime := ResearchTime + ProgrammingTime + SurfingTime + WastedTime + IdleTime
IniWrite, %ResearchTime%, track.txt, %thedate%, research
IniWrite, %ProgrammingTime%, track.txt, %thedate%, programming
IniWrite, %SurfingTime%, track.txt, %thedate%, surfing
IniWrite, %WastedTime% , track.txt, %thedate%, waste
IniWrite, %IdleTime% , track.txt, %thedate%, idle
IniWrite, %TotalTime% , track.txt, %thedate%, total
Return
FormatMinutes(NumberOfMinutes) ; Convert mins to hh:mm
{
Time := 19990101 ; *Midnight* of an arbitrary date
Time += %NumberOfMinutes%, minutes
FormatTime, HHmm, %Time%, HH '小时' mm '分钟'
Return HHmm
}
rctrl::
Gui, Font, s10, Microsoft YaHei
Gui, Add, Text, w150 Left, % "科研:`t" FormatMinutes(ResearchTime)
. "`n编程:`t" FormatMinutes(ProgrammingTime)
. "`n上网:`t" FormatMinutes(SurfingTime)
. "`n浪费:`t" FormatMinutes(WastedTime)
. "`n空闲:`t" FormatMinutes(IdleTime)
. "`n总计:`t" FormatMinutes(TotalTime)
Gui, -SysMenu
FormatTime, thedate, , yyyy/MM/dd
Gui, Show, , Track Log - %thedate%
Keywait, Esc, D T5
Gui, Destroy
Return
@ooker777
Copy link

I modify this script to emphasize the most important thing: the actual productivity time. The differences are:

  • English display
  • Only categorize the activities as Focused and Non-Focused. In the script, I term it as Dispassionated Concentration, because you have to feel dispassionate (or detachment) about your mental monkey in order to stop the procrastination. It is a Buddhism perspective, and related to mindfulness.
  • The focused time is large and emboldened.
  • Activation switches to NumLock

Apparently today I have spent 4 hours to write this script but only 45 minutes to read textbook. I hope once it's done this chronic situation can be reversed.

@TusharBaruah
Copy link

TusharBaruah commented Jan 25, 2024

This script is a modified AutoHotKey v2 port of RustingSword's v1 script. The changes made are:

  • Everything is rewritten to run using AutoHotKey v2 without issues.
  • The GUI display on pressing the right ctrl key is in English.
  • The Total Time no longer includes Idle Time. It is supposed to represent the screen time you have spent actively using your device.
  • Changes to the GUI design: Total Time is displayed bigger and in bold.

TB-timer_GUI

  • "timelog.txt", saved in the user's Documents folder, now has new keys to keep a record and quickly read the time spent in 'hh-mm' format for all previous dates.
  • The old v1 script updated the timer every minute. The script, by design, added 1 minute to a category if a corresponding app was active during the timer update. The major flaw is that if you spent 59 seconds using an app and then switched to another app, then after one more second, the timer will consider you spent 1 minute using the 2nd app and none using the 1st app.
  • A simple solution is to update the timer more often. Ideally, we would want a timer update every second. To prevent excessive and frequent function calls, this new v2 script updates the timer every 20 seconds. The error in tracking is reduced but, of course, not zero.
  • Usage category names have been changed to better suit personal needs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment