'---------------------------------------------------------------------- ' QuickLoggerPlus v2006072801 ' Appends the date and a line of text to a file. ' Based on QuickLogger: ' Credits from original QuickLogger: ' Based on code written by Joshua Fitzgerald, 7/2005. ' Modified by Gina Trapani, 7/2006. ' http://lifehacker.com/software/capture-tools/geek-to-live-quicklog-your-work-day-189772.php '---------------------------------------------------------------------- ' LICENSE ' No license was specified for the original lifehacker release. Because of this, I (Kirk Friggstad) ' am unable to specify a particular license for my changes to the original script. If the license ' for the original release is an OSI-certified license (GPL, MPL, MIT, Artistic, etc.), then my ' changes will be under the same license. Until the license for the original is determined, please ' do not redistribute my changes without the permission of the copyright holder(s) of the original ' release. Please keep these comments in any redistribution, unless a requirement to do so ' conflicts with the license used for the original release. I am not a lawyer, this so-called ' "license" section will probably not hold up in court, but I'm trying to do the right thing. Work ' with me here, people. ' UPDATE 2006-07-28 ' Gina Trapani has informed me that she does not have contact information for Joshua Fitzgerald. ' I'm releasing my changes to the public domain. If you make changes, I'd appreciate a copy ' back, but it's not required. '---------------------------------------------------------------------- ' CHANGELOG: ' 2006-07-28 - Kirk Friggstad (friggstadk@gmail.com) ' updated license information (contact info for JF) ' first public release (please be kind!) - posted to comments on Lifehacker ' 2006-07-27 - Kirk Friggstad (friggstadk@gmail.com) ' added CurrentTimestamp global variable ' fixed bug (adding blank line to log when Cancel pressed or nothing entered) ' added License section to documentation ' added file rotation periods (daily, weekly, monthly, quarterly, yearly) ' added automatic creation of non-existent directories ' 2006-07-26 - Kirk Friggstad - (friggstadk@gmail.com) ' added ISO timestamp option ' added file rotation option ' added shortcut to current log file option ' added comments / documentation ' changed simple little 23-line script to semi-bloated 100+ line monster '---------------------------------------------------------------------- ' TODO: ' high priority ' N/A ' medium priority ' feature: alternate logging formats (HTML table, XML, etc.) ' feature: logging to online service (XMLRPC? AJAX? OMGWTFLOLBBQ?) ' low priority ' feature: configure more options for shortcut (custom icon, ' preferred text viewer, hotkey, etc.) '---------------------------------------------------------------------- Option Explicit ' set the following variables to fit your preferences and installation: Dim filenamebase, filetype, filename, rotatefiles, useISOtimestamp, _ useShortcut, shortcutPath, shortcutDescription, rotationPeriod, firstdayofweek ' filenamebase: String - path to log file, not including extension filenamebase = "C:\Documents and Settings\Kirk\My Documents\Worklog\worklog" ' filetype: String - "txt", "log", etc. filetype = "txt" ' rotatefiles: Boolean - create new file each time period rotatefiles = True ' rotationPeriod: Character - time period for rotating files ' valid values are "D", "W", "M", "Q", or "Y" ' if unspecified, defaults to "D" rotationPeriod = "W" ' firstDayOfWeek: Integer - what day is first day of the week ' 1 = Sunday, 2 = Monday, etc. firstdayofweek = 1 ' useISOtimestamp: Boolean ' True: use ISO timestamps (see http://www.cl.cam.ac.uk/~mgk25/iso-time.html for details) ' False: use default local setting for time format useISOtimestamp = True ' useShortcut: Boolean - maintain a shortcut to current file ' (useful in conjunction with rotatefiles=True) useShortcut = False ' shortcutPath: String - full path to shortcut (.lnk) file shortcutPath = "C:\Documents and Settings\kirk\My Documents\My Toolbars\Quick Access\Work Log.lnk" ' shortcutDescription: String - description of shortcut (shows on hover, etc.) shortcutDescription = "Current QuickLoggerPlus log file" '---------------------------------------------------------------------- ' NO USER CONFIGURABLE VARIABLES BELOW THIS LINE ' ABANDON HOPE ALL YE WHO ENTER HERE '---------------------------------------------------------------------- dim CurrentTimestamp CurrentTimestamp = Now() if rotatefiles then Dim dateforfilename, dateoffset select case rotationPeriod case "Y": dateoffset = DatePart("y", CurrentTimestamp) - 1 case "Q": dateoffset = DateDiff("d", DateSerial(year(CurrentTimestamp), 1 + 3*(DatePart("q", CurrentTimestamp)-1), 1), CurrentTimestamp) case "M": dateoffset = Day(CurrentTimestamp) - 1 case "W": dateoffset = Weekday(CurrentTimestamp, firstdayofweek) -1 case else dateoffset = 0 end select dateforfilename = DateAdd("d", (dateoffset * -1), CurrentTimestamp) filename = filenamebase & CurrentISOdate(dateforfilename) & "." & filetype else filename = filenamebase & "." & filetype end if Dim text text = InputBox("Add to " & filename & ":", "Quick Logger Plus") if len(text) > 0 then WriteToFile(text) if useShortcut then UpdateShortcut end if Sub WriteToFile(text) Dim fso Dim textFile Set fso = CreateObject("Scripting.FileSystemObject") ' check for existence of directories dim arrFolderPath, myIndex, myFilepath filename = replace(filename, "/", "\") arrFolderPath = split(filename, "\") myFilePath = arrFolderPath(0) for myIndex = 1 to UBound(arrFolderPath) - 1 if len(arrFolderPath(myIndex)) > 0 then myFilePath = myFilePath + "\" + arrFolderPath(myIndex) if not fso.FolderExists(myFilePath) then fso.CreateFolder myFilePath end if next Set textFile = fso.OpenTextFile(filename, 8, True) if useISOtimestamp then textFile.WriteLine CurrentISOtimestamp & " " & text else textFile.WriteLine Now & " " & text end if textFile.Close End Sub Function CurrentISOdate(byVal myCurrentTimestamp) Dim myISOdate myISOdate = CStr(Year(myCurrentTimestamp)) if Month(myCurrentTimestamp) < 10 then myISOdate = myISOdate & "-0" & Month(myCurrentTimestamp) else myISOdate = myISOdate & "-" & Month(myCurrentTimestamp) end if if Day(myCurrentTimestamp) < 10 then myISOdate = myISOdate & "-0" & Day(myCurrentTimestamp) else myISOdate = myISOdate & "-" & Day(myCurrentTimestamp) end if CurrentISOdate = myISOdate End Function Function CurrentISOtimestamp Dim myISOtimestamp CurrentTimestamp = Now myISOtimestamp = CStr(Year(CurrentTimestamp)) if Month(CurrentTimestamp) < 10 then myISOtimestamp = myISOtimestamp & "-0" & Month(CurrentTimestamp) else myISOtimestamp = myISOtimestamp & "-" & Month(CurrentTimestamp) end if if Day(CurrentTimestamp) < 10 then myISOtimestamp = myISOtimestamp & "-0" & Day(CurrentTimestamp) else myISOtimestamp = myISOtimestamp & "-" & Day(CurrentTimestamp) end if if Hour(CurrentTimestamp) < 10 then myISOtimestamp = myISOtimestamp & " 0" & Hour(CurrentTimestamp) else myISOtimestamp = myISOtimestamp & " " & Hour(CurrentTimestamp) end if if Minute(CurrentTimestamp) < 10 then myISOtimestamp = myISOtimestamp & ":0" & Minute(CurrentTimestamp) else myISOtimestamp = myISOtimestamp & ":" & Minute(CurrentTimestamp) end if if Second(CurrentTimestamp) < 10 then myISOtimestamp = myISOtimestamp & ":0" & Second(CurrentTimestamp) else myISOtimestamp = myISOtimestamp & ":" & Second(CurrentTimestamp) end if CurrentISOtimestamp = myISOtimestamp End Function Sub UpdateShortcut Dim myWSH, myShortcut set myWSH = CreateObject("WScript.Shell") set myShortcut = myWSH.CreateShortcut(shortcutPath) myShortcut.TargetPath = filename myShortcut.Description = shortcutDescription myShortcut.Save End Sub '---------------------------------------------------------------------- ' This is the end. Nothing else to see. '---------------------------------------------------------------------- '---------------------------------------------------------------------- ' No, really, nothing else to see. Stop already. '----------------------------------------------------------------------