Wednesday, March 31, 2010

ONE TEXT FILE TO RULE THEM ALL

Wow, it's been a year since I posted here and the only reason that I'm breaking my silent streak (other social media being much more interactive and fun) is that I am bursting with geeky pride over completing My System which I affectionately refer to as One Text File to Rule Them All.

I got the idea of working from a Big Ass Text File from this post on 43 folders. Being forced to use WordPerfect at work increased my desire to have most of my stuff in an almost completely incorruptible format, namely the humble plaintext txt or flat file as it is sometimes called.

Development
I used AutoHotKey to create a way to quickly input data from any of my computers, because the script and the text file (to rule them all) both reside in my DropBox folder. Run the script and it waits of me to press the key combination of Control+Spacebar which brings up this interface:

Whatever I type can be categorized into my stream-of-consciousness journal, placed in my knowledge database (bookmarks, quotes, etc), added to my wish list (book titles, software), added to my Do or Now lists (to do and next actions respectively), included in my list of half-baked ideas or saved to the text file and uploaded to Twitter automatically (the number at the bottom of the dialog counts your letters for tweeting purposes). When this window is up, you can use Ctrl+First letter shortcuts. I also have hotkeys set up to bring up each of these lists separately (Win+Letter) which can be accessed even if the dialog is not active.
To inactivate an item one must only open any of the lists and press Win+R (for remove). The text file will still contain this item, but it won't be sent to the sublists. I also put in a hotkey (Win+x) which clips whatever you have highlighted directly to the txt file with a datestamp and #clipped hashtag.

Now, no self-respecting programmer would be proud of this. It's a good thing that I am not a programmer and also possess no self respect.

Script provided below requires AutoHotKey and httpQUERY.ahk (in the same folder). Unless you give me your twitter username and password and I can create you a .exe - how much do you trust me?


; ONE TEXT FILE TO RULE THEM ALL
;
; Install - place httpQUERY.ahk in the same folder with this script. The ONE TEXT

FILE TO RULE THEM ALL
; and the temporary sub files will be in the same folder. Runs great in your

MyDropBox folder.
;
; Instructions:
; Ctrl-Space opens dialog
; Win-Space opens the One Text File
; Win-x copies (appends) to the one text file without switching screens (adds

#clipped hashtag)
; KEY below
;® Do Items Win+d opens a file of Do items
;¤ Now Items Win+n
;§ Wish Items Win+w
;© Half-Baked Items Win+h
;¶ Knowledge Items Win+k
;¦ Journal Item Win+j
;« Calendar Item Win+c
;µ Tweet Item Win+t
;¥ (reserved for future use)
;
; To inactivate (but not delete it from your OTF, highlight the datestamp and

press Win+r (for remove)
;
; Code to post to twitter from agdurrette:

http://www.autohotkey.com/forum/viewtopic.php?t=45459&highlight=twitter

#NoEnv
#Persistent
#SingleInstance, Force
SendMode Input
SetTitleMatchMode 2
SetWorkingDir %A_ScriptDir%
#include %A_ScriptDir%\httpQuery.ahk

Gui, Add, Edit, x6 y10 w310 h20 gUpdateChar vData ,
Gui, Add, Button, x6 y40 w70 h30 default, &Journal
Gui, Add, Button, x6 y80 w70 h30, &Knowledge
Gui, Add, Button, x86 y40 w70 h30, &Calendar
Gui, Add, Button, x86 y80 w70 h30, &Tweet
Gui, Add, Button, x166 y40 w70 h30, &Wish
Gui, Add, Button, x166 y80 w70 h30, &HalfBaked
Gui, Add, Button, x246 y40 w70 h30, &Do
Gui, Add, Button, x246 y80 w70 h30, &Now
Gui, Add, Text, x6 y120 w200 h20 vCounter,

;This just provides a counter in the GUI of how many characters you have written

(useful for Twitter posts)
UpdateChar:
GuiControlGet, Status,, Data
stringlen cnt, Status
GuiControl Text, Counter, %cnt%
Return

;This posts a tweet to Twitter - change "username" and "password" to yours
Post:
{
URL := "http://username:password@twitter.com/statuses/update.xml?"
POSTdata := "status="status
httpQUERY(buffer:="",URL,POSTdata)
}
Return

^Space::
GuiControl,,Data,
Gui, Show,,One Text File to Rule Them All
Sleep, 50
ControlFocus, Edit1, OTFTRTA
Return

#Space::
Run OTFTRTA.txt
ControlFocus,,OTFTRTA
Sleep, 500
Send ^{End}
Return

; Used this for a moment to sumbit True to SQL
;#z::
;Send, True`n
;Return

;Destroys the old versions of the organized text output files and recreates them

with the most recent data
;I could do this by reading in variables, but this is easier to read and change in

the future
Refreshlists:
FileDelete, anything.txt
FileDelete, Do.txt
FileDelete, Now.txt
FileDelete, Journal.txt
FileDelete, Wish.txt
FileDelete, Calendar.txt
FileDelete, HalfBaked.txt
FileDelete, Knowledge.txt
FileDelete, Tweet.txt
FileDelete, Clipped.txt

;Make copies of the first one of these to create separate files for anything you

want with a hashtag
Loop, read, OTFTRTA.txt, anything.txt
{
IfInString, A_LoopReadLine, #anything, FileAppend, %A_LoopReadLine%`n
}
Loop, read, OTFTRTA.txt, clipped.txt
{
IfInString, A_LoopReadLine, #clipped, FileAppend, %A_LoopReadLine%`n
}
Loop, read, OTFTRTA.txt, Do.txt
{
IfInString, A_LoopReadLine, ®, FileAppend, %A_LoopReadLine%`n
}
Loop, read, OTFTRTA.txt, Now.txt
{
IfInString, A_LoopReadLine, ¤, FileAppend, %A_LoopReadLine%`n
}
Loop, read, OTFTRTA.txt, Journal.txt
{
IfInString, A_LoopReadLine, ¦, FileAppend, %A_LoopReadLine%`n
}
Loop, read, OTFTRTA.txt, Knowledge.txt
{
IfInString, A_LoopReadLine, ¶, FileAppend, %A_LoopReadLine%`n
}
Loop, read, OTFTRTA.txt, Calendar.txt
{
IfInString, A_LoopReadLine, «, FileAppend, %A_LoopReadLine%`n
}
Loop, read, OTFTRTA.txt, Tweet.txt
{
IfInString, A_LoopReadLine, µ, FileAppend, %A_LoopReadLine%`n
}
Loop, read, OTFTRTA.txt, Wish.txt
{
IfInString, A_LoopReadLine, §, FileAppend, %A_LoopReadLine%`n
}
Loop, read, OTFTRTA.txt, HalfBaked.txt
{
IfInString, A_LoopReadLine, ©, FileAppend, %A_LoopReadLine%`n
}
Return

;This part clips what is highlighted to the OTFTRTA without changing screens. You

get a wee little beep
;as evidence that it worked.
#x::
clipboard=
Send, ^c
ClipWait, 2
if ErrorLevel
{
MsgBox, The attempt to copy text onto the clipboard failed.
return
}
fileappend ¦ %clipboard% %CurrentDateTime% #clipped`n, OTFTRTA.txt
SoundBeep 3000, 5
Gosub, Refreshlists
return

ButtonDo:
FormatTime, CurrentDateTime,, yyyyMMddHHmmss
Gui, Submit
FileAppend, ® %data% %CurrentDateTime%`n, OTFTRTA.txt
Gui, Hide
Gosub, Refreshlists
Return

ButtonCalendar:
FormatTime, CurrentDateTime,, yyyyMMddHHmmss
Gui, Submit
FileAppend, « %data% %CurrentDateTime%`n, OTFTRTA.txt
Gui, Hide
Gosub, Refreshlists
Return

ButtonWish:
FormatTime, CurrentDateTime,, yyyyMMddHHmmss
Gui, Submit
FileAppend, § %data% %CurrentDateTime%`n, OTFTRTA.txt
Gui, Hide
Gosub, Refreshlists
Return

ButtonNow:
FormatTime, CurrentDateTime,, yyyyMMddHHmmss
Gui, Submit
FileAppend, ¤ %data% %CurrentDateTime%`n, OTFTRTA.txt
Gui, Hide
Gosub, Refreshlists
Return

ButtonKnowledge:
FormatTime, CurrentDateTime,, yyyyMMddHHmmss
Gui, Submit
FileAppend, * %data% %CurrentDateTime%`n, OTFTRTA.txt
Gui, Hide
Gosub, Refreshlists
Return

ButtonTweet:
FormatTime, CurrentDateTime,, yyyyMMddHHmmss
Gui, Submit
FileAppend, µ %data% %CurrentDateTime%`n, OTFTRTA.txt
Gosub, Post
Gui, Hide
Gosub, Refreshlists
Return

ButtonHalfBaked:
FormatTime, CurrentDateTime,, yyyyMMddHHmmss
Gui, Submit
FileAppend, ¶ %data% %CurrentDateTime%`n, OTFTRTA.txt
Gui, Hide
Gosub, Refreshlists
Return

ButtonJournal:
FormatTime, CurrentDateTime,, yyyyMMddHHmmss
Gui, Submit
FileAppend, ¦ %data% %CurrentDateTime%`n, OTFTRTA.txt
Gui, Hide
Gosub, Refreshlists
Return

#w::
Run Wish.txt
ControlFocus,,Wish
Sleep, 500
Send ^{End}
Return

#d::
Run Do.txt
ControlFocus,,do
Sleep, 500
Send ^{End}
Return

#j::
Run journal.txt
ControlFocus,,Journal
Sleep, 500
Send ^{End}
Return

#n::
Run now.txt
ControlFocus,,Now
Sleep, 500
Send ^{End}
Return

#t::
Run tweet.txt
ControlFocus,,Tweet
Sleep, 500
Send ^{End}
Return

#c::
Run calendar.txt
ControlFocus,,Calendar
Sleep, 500
Send ^{End}
Return

#h::
Run halfbaked.txt
ControlFocus,,HalfBaked
Sleep, 500
Send ^{End}
Return

#k::
Run knowledge.txt
ControlFocus,,Knowledge
Sleep, 500
Send ^{End}
Return

#r::
Gosub, MakeOld

Return
MakeOld:
send ^c
Loop, read, OTFTRTA.txt, MyTempFile.txt ; designate an output file
{
temp := ( A_Index = 1 ? "" : "`n" ) . A_LoopReadLine
IfInString, temp, %clipboard%
{
stringreplace,temp,temp,®,OldDo
stringreplace,temp,temp,¤,OldNow
stringreplace,temp,temp,§,OldWish
stringreplace,temp,temp,©,OldHalf
stringreplace,temp,temp,«,OldCal
stringreplace,temp,temp,¶,OldKnow
stringreplace,temp,temp,¦,OldJournal
stringreplace,temp,temp,µ,OldTweet
}
FileAppend, %temp%
}
FileMove, MyTempFile.txt, OTFTRTA.txt, 1 ; overwrite the source file.
Gosub, refreshlists
return


;The following submit based on keystrokes (only if the OTFTRTA is open) with the

appropriate headers
#IfWinActive OTFTRTA ahk_class AutoHotkeyGUI
^d::
FormatTime, CurrentDateTime,, yyyyMMddHHmmss
Gui, Submit
FileAppend, ® %data% %CurrentDateTime%`n, OTFTRTA.txt
Gui, Hide
Gosub, Refreshlists
Return


#IfWinActive OTFTRTA ahk_class AutoHotkeyGUI
^n::
FormatTime, CurrentDateTime,, yyyyMMddHHmmss
Gui, Submit
FileAppend, ¤ %data% %CurrentDateTime%`n, OTFTRTA.txt
Gui, Hide
Gosub, Refreshlists
Return

#IfWinActive OTFTRTA ahk_class AutoHotkeyGUI
^w::
FormatTime, CurrentDateTime,, yyyyMMddHHmmss
Gui, Submit
FileAppend, § %data% %CurrentDateTime%`n, OTFTRTA.txt
Gui, Hide
Gosub, Refreshlists
Return

#IfWinActive OTFTRTA ahk_class AutoHotkeyGUI
^h::
FormatTime, CurrentDateTime,, yyyyMMddHHmmss
Gui, Submit
FileAppend, © %data% %CurrentDateTime%`n, OTFTRTA.txt
Gui, Hide
Gosub, Refreshlists
Return

#IfWinActive OTFTRTA ahk_class AutoHotkeyGUI
^k::
FormatTime, CurrentDateTime,, yyyyMMddHHmmss
Gui, Submit
FileAppend, ¶ %data% %CurrentDateTime%`n, OTFTRTA.txt
Gui, Hide
Gosub, Refreshlists
Return

#IfWinActive OTFTRTA ahk_class AutoHotkeyGUI
^j::
FormatTime, CurrentDateTime,, yyyyMMddHHmmss
Gui, Submit
FileAppend, ¦ %data% %CurrentDateTime%`n, OTFTRTA.txt
Gui, Hide
Gosub, Refreshlists
Return

#IfWinActive OTFTRTA ahk_class AutoHotkeyGUI
^c::
FormatTime, CurrentDateTime,, yyyyMMddHHmmss
Gui, Submit
FileAppend, « %data% %CurrentDateTime%`n, OTFTRTA.txt
Gui, Hide
Gosub, Refreshlists
Return

#IfWinActive OTFTRTA ahk_class AutoHotkeyGUI
^t::
FormatTime, CurrentDateTime,, yyyyMMddHHmmss
Gui, Submit
FileAppend, µ %data% %CurrentDateTime%`n, OTFTRTA.txt
Gosub, Post
Gui, Hide
Gosub, Refreshlists
Return

#IfWinActive OTFTRTA ahk_class AutoHotkeyGUI
Escape::
Gui, Hide
Return