Aloha,
After quite a long time of more-or-less forced abstinence, I've written a little AHK script again. It's not completely finished yet, but it's only missing comfort functions, and I thought I'd share it.
The idea's inspired by a
Lifehacker posting (and a
particular comment) - my adaptiation is meant to help you logging your life!
Sounds somewhat scary, eh - well, I created it to better keep track of important events (e.g. renewed magazine subscriptions, purchases etc.) and to quickly record things that pop into my mind (e.g. ideas - but also things like vocabulary or other stuff I pick up).
Here's how it works: Assign a keyboard combo (by editing a Windows shortcut to the EXE; e.g. [CTRL]+[ALT]+[L]) that starts the script, and it will present you with a simple GUI consisting of three input fields;
Timestamp,
Description and
Tag(s).
The timestamp is filled in automatically, the description contains the actual item and the last column contains tags (duh!) which are meant to facilitate retrieval later on.
These entries are stored in a CSV-like file - here's a random example of what that might look like:
Code:
Timestamp || Description || Tag(s)
2006-11-03 14:49 || renewed Newsweek subscription || magazine money purchase
2006-11-05 18:23 || LifeLogger: tag selection list || dev
2006-11-06 15:30 || ahead of the pack || vocab:phrase
However, I have to admit that I myself don't really have the discipline/memory to always log everything I'd want to, which kinda defeats the purpose. Also, it can be a bit of a hassle to create (and stick to) a consistent vocabulary for the tagging.
Anyways, enough of the description, let the code talk (scroll down for the required INI):
Code:
/*
LifeLogger v0.85
by FND
Simple interface to quickly create short entries in a CSV-like log file.
Inspired by QuickLoggerPlus by Kirk Friggstad, which is based on QuickLogger
by Gina Trapani, which in turn is based on (VBS) code by Joshua Fitzgerald.
*/
/*
ToDo:
- add option to create backups
- add selection list for (recently/frequently used) tags
- add options menu
- option to use different tag files for each log file
- integrate xSV Editor (external module => pass column separator)
- add encryption (optional); per-entry basis (problematic!?)
- add option to auto-rotate filenames (new file each day/week/month/year)
*/
/*
Changelog
¯¯¯¯¯¯¯¯¯
# v0.85 (2007-02-12)
* removed tray icon
* added command line switch "-l" for specifying active log file
* made ESC hotkey context-sensitive (triggered only when script window is active)
* re-arranged configuration file
* fixed default settings: time now in 24-hour format, Windows mode for linefeeds
# v0.8 (2006-11-06)
* first version based on QuickLogger++ (unreleased adaptation of QuickLoggerPlus)
* added tagging functionality to the original concept
*/
/*
********** settings, variable declarations **********
*/
#SingleInstance Force
#NoEnv
#NoTrayIcon
OnExit, quit
programName = LifeLogger
programVersion = 0.85
programFullName = %programName% v%programVersion%
programAuthor = FND
configFile = LifeLogger.ini
/*
********** auto-execute section **********
*/
; getSettings
GoSub, getSettings
; process command line parameters
GoSub, getParams
; get current time
GoSub, getTime
; construct GUI
GoSub, showGUI
; define this script's windows (required for context-sensitive hotkeys)
GroupAdd, thisScript, %programName%
; end of auto-execute section
Return
/*
********** hotkeys **********
*/
; [ESC]: terminate script
#IfWinActive, ahk_group thisScript
Esc::
Suspend ; exempt from suspension
GoSub, quit
Return
/*
********** subroutines **********
*/
; process command line parameters
getParams:
Loop, %0% ; for each command line parameter
{
; "-l": active log file
If (%A_Index% = "-l")
param := A_Index + 1
logFile := %param%
}
Return
; construct GUI
showGUI:
; menu bar
Menu, fileMenu, Add, Select active &log, logFileSelect
Menu, fileMenu, Add, Show &active log, logFileOpen
Menu, fileMenu, Add
Menu, fileMenu, Add, E&xit, quit
Menu, HelpMenu, Add, &About, about
Menu, menuBar, Add, &File, :fileMenu
Menu, menuBar, Add, &?, :HelpMenu
Gui, Menu, menuBar
; GUI items
Gui, Font, Bold
Gui, Add, Text, x6 y7 w100, %timestampHeading%
Gui, Font, Norm
Gui, Add, Edit, x6 y27 w100 vTimestamp, %now%
Gui, Font, Bold
Gui, Add, Text, x116 y7 w300, %descHeading%
Gui, Font, Norm
Gui, Add, Edit, x116 y27 w300 vDesc,
Gui, Font, Bold
Gui, Add, Text, x426 y7 w150, %tagsHeading%
Gui, Font, Norm
Gui, Add, Edit, x426 y27 w150 vTags,
Gui, Add, Button, x366 y67 w100, Cancel
Gui, Add, Button, x476 y67 w100 default, OK
Gui, Show ,, %programName%
; skip timestamp field
If (skipTimestamp = True)
{
Send, {Tab} ; DEBUG: dirty hack!?
}
Return
ButtonOK:
; save inputs
Gui, Submit
; trim leading and trailing spaces
timestamp = %timestamp%
desc = %desc%
tags = %tags%
; write to log file
GoSub, writeLog
; terminate script
GoSub, quit
Return
logFileSelect:
FileSelectFile, logFile, 2, %A_WorkingDir%
, Please specify the name of the file to write log entries to.
Return
logFileOpen:
IfExist, %logFile%
Run, %logFile%
Else
MsgBox, Log file does not exist.
Return
ButtonCancel:
GuiClose:
GoSub, quit
Return
; write to log file
writeLog:
; check for invalid chars
checkValidity(timestamp, "Timestamp")
checkValidity(desc, "Description")
checkValidity(tags, "Tag")
; create log file with column headings if it doesn't exist already
IfNotExist, %logFile%
FileAppend
, % timestampHeading . separator . descHeading . separator . tagsHeading . "`n"
, %lfModifier%%logFile%
; write to file
FileAppend
, % timestamp . separator . desc . separator . tags . "`n"
, %lfModifier%%logFile%
Return
; get current time
getTime:
If (useUTC = True)
{
FormatTime, now, %A_NowUTC%, %timeFormat%
}
Else
{
FormatTime, now, %A_Now%, %timeFormat%
}
Return
; read user settings
getSettings:
; create config file if it does not exist yet
IfNotExist, %configFile%
GoSub, writeSettings
; read settings from file
IniRead, logFileBase, %configFile%, logFiles, logFileBase
IniRead, logFileExt, %configFile%, logFiles, logFileExt
IniRead, tagFileBase, %configFile%, logFiles, tagFileBase
IniRead, tagFileExt, %configFile%, logFiles, tagFileExt
IniRead, skipTimestamp, %configFile%, interface, skipTimestamp
IniRead, unixMode, %configFile%, CsvFormat, unixMode
IniRead, useUTC, %configFile%, CsvFormat, useUTC
IniRead, timeFormat, %configFile%, CsvFormat, timeFormat
IniRead, separator, %configFile%, CsvFormat, separator ; DEBUG: filter potentially problematic chars (e.g. "`")!?
IniRead, timestampHeading, %configFile%, columnHeadings, timestamp
IniRead, descHeading, %configFile%, columnHeadings, desc
IniRead, tagsHeading, %configFile%, columnHeadings, tags
; convert True/False strings to actual boolean values
stringToBoolean(skipTimestamp)
stringToBoolean(unixMode)
stringToBoolean(useUTC)
; process settings
logFile = %logFileBase%.%logFileExt%
tagFile = %tagFileBase%.%tagFileExt%
If (unixMode = True)
lfModifier = * ; use Unix mode for linefeeds (LF)
Else
lfModifier = ; use Windows mode for linefeeds (CR+LF)
Return
; write user settings - DEBUG: to do (currently just for initialization)
writeSettings:
IniWrite, LifeLogger, %configFile%, logFiles, logFileBase
IniWrite, log, %configFile%, logFiles, logFileExt
IniWrite, tags, %configFile%, logFiles, tagFileBase
IniWrite, lst, %configFile%, logFiles, tagFileExt
IniWrite, True, %configFile%, interface, skipTimestamp
IniWrite, False, %configFile%, CsvFormat, unixMode
IniWrite, True, %configFile%, CsvFormat, useUTC
IniWrite, yyyy-MM-dd HH:mm, %configFile%, CsvFormat, timeFormat
IniWrite, |, %configFile%, CsvFormat, separator
; log file format
IniWrite, Timestamp, %configFile%, columnHeadings, timestamp
IniWrite, Description, %configFile%, columnHeadings, desc
IniWrite, Tag(s), %configFile%, columnHeadings, tags
Return
; check for invalid chars
checkValidity(ByRef var, varTitle)
{
Global separator
Global programName
If var Contains %separator%
{
MsgBox, 0, %programName%,
( LTrim
Error: %varTitle% contains column separator.
Respective characters will be removed automatically.
)
cleanse(var, "")
}
}
; remove potentially problematic chars
cleanse(ByRef string, cleanChar)
{
; remove column separators
Global separator
StringReplace, string, string, %separator%, %cleanChar%, All
}
; convert True/False strings to actual boolean values
stringToBoolean(ByRef var)
{
If var = True
var := True
Else
var := False
}
; show info message
about:
MsgBox, 64, %programFullName%,
( LTrim
%programFullName%
%A_Space%by %programAuthor%
Simple interface to quickly create short entries in a CSV-like log file.
Inspired by QuickLoggerPlus by Kirk Friggstad, which is based on QuickLogger
by Gina Trapani, which in turn is based on (VBS) code by Joshua Fitzgerald.
Use [ESC] to terminate the program.
)
Return
; terminate script
quit:
; terminate script
ExitApp
Return
Let me know what you think of the idea and the implementation, respectively.
Update: v0.85 (2007-02-12) released