Saturday, January 16, 2016

Text-File Wiki, Again

Some time ago, I wrote a post on the Donation Coder by "cedardoc" that offered a most interesting script for keeping text files in a directory and to connect them by means of wiki links," thus creating a small, primitive, but working personal wiki.

I fooled around with it and changed it considerably from the original version:
    The most important change is that the text files now have the extension "wki". Can be changed to anything you like. Advantage: you don't need to type "[projects.txt]" or "[projects.wki]", but just projects.
  • Another change is that it I added some auto executing code at the beginning that re-loads the script automatically after it was edited
  • Third, I eliminated the need to click "O.K." when a topic does not exist and needs to be created. (This is closer to the way wikis behave, anyway; and was it already in my original revision.)
  • I have added "Send, `n{BS}{BS}" This became necessary, as the editor I use for this inserts a garbage characters when I re-open a text file. (You may not need it, if you use another text editor).

The texteditor I use explicitly for this is Quickpad. It is "a small and very fast Notepad-like application. It can be always running without being in your way, saves your notes automatically, is fully controllable through keyboard shortcuts and - as a special feature - divides (text) files virtually into several pages." Furthermore, "QuickPad 'TinyApp' Edition ships without setup routine as its uninstallation consists only of deleting the files it creates."

I have associated Quickpad with the "wki" extension, and I keep it in the same directory as the wki files. (You could use any other editor for this as well, as long as you associate it with wki files or change "wki" to "txt" or whatever.

I have used this for a little while now. It works for me! If anyone decides to use it and has problems, please let me know.

One of the things I am still thinking about is how to remove the restriction that there can only be one link per line. Any suggestions would be welcome.

Oh ... And a big thank you to "cedardoc", whoever he may be.[1]

; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win9x/NT
; Author:         A.N.Other 
; Script Function:
; Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)

SplashTextOn,,,Updated script, 

#SingleInstance force
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

;right mouse double click---------autohotkey to launch simple filename (cursor should be on line )

If (A_PriorHotKey = A_ThisHotKey and A_TimeSincePriorHotkey < 500)

Sleep 250  ;wait for right-click menu, fine tune for your PC

send !{Home}{Home}+{End}
sleep 100

send ^c  ;selects the entire line and copies it
sleep 100

sleep 100

send {home}
linestring = %clipboard%

sleep 500

;find the position of the character "[", call it leftmark
bit1 = [  
StringGetPos, leftmark, linestring, %bit1%
leftmark := leftmark + 2
;find the position of the character "]", call it rightmark
bit2 = ]  
StringGetPos, rightmark, linestring, %bit2%
rightmark := rightmark + 1
stringlength := rightmark - leftmark
thefile := SubStr(linestring, leftmark , stringlength)
thefilename = %thefile%.wki
IfExist, %thefilename%
run %thefilename%
Sleep, 300
Send, `n{BS}{BS}
IfNotExist, %thefilename%
FileAppend, %thefilename%, %thefilename%
run, %thefilename%
1. The approach in this script is rather different from my Notetab wiki, AhKWikiPad, and Roughdraft wiki

No comments: