Monday, December 30, 2013

Another Simple Text Wiki with Autohotkey

I came across Donation Coder post on "a structured plain text note taker." It really amounts to a primitive wiki. I cleaned up the AhK, modified it, and—I hope—improved it a little. As cedardoc, the original author, put it: "I just had to add this really low tech approach to the txt file note approach. You keep them all in one folder and refer to other notes (works with txt and rtf or whatever) and refer to other notes by using square brackets like this [projects.txt] as long as there's only one listed per line, then just have this script in a running autohotkey file from the same folder":

#SingleInstance force

#NoEnv  
SendMode Input  
SetWorkingDir %A_ScriptDir%  

^l::
clipboard =
send, {esc}{Home}+{End}
Sleep 200
Send, ^c
Send, ^s
sleep, 200

clipboard = %clipboard%
linestring := clipboard
sleep 100
Send !fs
Send !fx

bit1 = [[ ;find the position of the character "[", call it leftmark
StringGetPos, leftmark, linestring, %bit1%
leftmark := leftmark + 3

bit2 = ]] ;find the position of the character "]", call it rightmark
StringGetPos, rightmark, linestring, %bit2%
rightmark := rightmark + 1

stringlength := rightmark - leftmark
thefilename := SubStr(linestring, leftmark , stringlength)".txt"
topicname := SubStr(linestring, leftmark , stringlength)

IfExist, %thefilename%
    {
    run %thefilename%
    sleep 100
    Send, ^{End}
    }
IfNotExist, %thefilename%
    {
    FileAppend, %topicname%, %thefilename%
    run %thefilename%
    sleep 100
    Send ^{End}
    }
else
    return
return

To use it, just enclose any word or phrase you want to use as a link in double brackets and press Ctrl-l.

This little script "implements" only very basic functions of a personal wiki, not, of course, those of an online wiki.

It can easily be modified for use with other formats or applications. If you use "text" as an extension, then Texts will work with it and you will have a not-so-primitive Markdown wiki (with footnotes and tables). It will also be WYSIWYG.

No comments: