; ; AutoHotkey Version: 1.x ; Language: English ; Platform: Win9x/NT ; Author: Wade Armstrong ; ; Script Function: ; Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder) ; #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. SendMode Input ; Recommended for new scripts due to its superior speed and reliability. #SingleInstance force thefile=C:\Documents and Settings\username\My Documents\your_bonsai_file.otl ; access this date to put in the created-on date thedate=%A_DD% %A_MMMM% %A_YYYY% %A_Hour%:%A_Min% ; Now pop a dialog asking for the line to add Gui, Add, Text,, Entry content Gui, Add, Edit, w600 vContent Gui, Add, Button, Default, Add Gui, Show, Center Return ButtonAdd: Gui, Submit Gui, Destroy ; Add our new node with our user-inputted content errors += XMLWrite(thefile, "bonsai-outline.items.item[-1]", "","" , "IndT") errors += XMLWrite(thefile, "bonsai-outline.items.item[0]", "todo", "attribute['type']") errors += XMLWrite(thefile, "bonsai-outline.items.item[0]", thedate, "attribute['create-date']") errors += XMLWrite(thefile, "bonsai-outline.items.item[0]", thedate, "attribute['last-modified']") errors += XMLWrite(thefile, "bonsai-outline.items.item[0]", "0", "attribute['percent-complete']") errors += XMLWrite(thefile, "bonsai-outline.items.item[0].text[+1]", Content, "", "IndT") If errors > 0 MsgBox, There were %errors% errors in writing to file %thefile%. ExitApp GuiEscape: Gui, Destroy ExitApp ; The XMLWrite function comes from Titan ; Find it at http://www.autohotkey.net/~Titan/dl/XMLWrite-Doc.html XMLWrite(file, tree, data, type="", options="") { ; by Titan - version 1.04 xBL =%A_BatchLines% SetBatchLines, -1 xSC =%A_StringCaseSense% StringCaseSense, On xAT =%A_AutoTrim% AutoTrim, Off FileRead, s, %file% StringReplace, tree, tree, (, [, 1 StringReplace, tree, tree, ), ], 1 StringReplace, type, type, (, [, 1 StringReplace, type, type, ), ], 1 If options { StringReplace, op, options, %A_Tab%, %A_Space%, 1 op =%A_Space%%op%%A_Space% If InStr(op, " Ind") { StringTrimLeft, op_ind, op, InStr(op, " Ind") - 1 + StrLen(" Ind") StringLeft, op_ind, op_ind, InStr(op_ind, " ") - 1 StringReplace, op_ind, op_ind, S, %A_Space%, 1 StringReplace, op_ind, op_ind, T, %A_Tab%, 1 } } If InStr(s, "?>") { StringLeft, p, s, InStr(s, "?>") + 1 StringTrimLeft, s, s, InStr(s, "?>") + 1 } Loop, Parse, tree, . { e =%A_LoopField% op_s := "" If InStr(op, " Ind") { Loop, % A_Index - 1 op_s =%op_s%%op_ind% StringTrimRight, op_sa, op_s, 1 op_s =`r`n%op_s% op_sa =`r`n%op_sa% } If InStr(e, "[") and InStr(e, "]") { StringMid, i, e, InStr(e, "[") + 1, InStr(e, "]") - InStr(e, "[") - 1 StringReplace, e, e, [%i%] If i is not integer error := true } Else i =0 StringReplace, s, s, <%e%>, <%e%%A_Space%>, 1 If !(InStr(s, "<" . e . " ", 1) or InStr(s, "<" . e . ">", 1)) i =+1 If (InStr(i, "+") or InStr(i, "-")) and (i != "+0" and i != "-0") { If (i < 0) { StringLeft, t, s, InStr(s, ">") r =%r%%t% StringTrimLeft, s, s, InStr(s, ">") o =%s%%o% If InStr(op, "fused ") s =%op_s%<%e% />%op_sa% Else s =%op_s%<%e%>%op_sa% Loop, % (i * -1) - 1 If InStr(op, "fused ") o =%op_s%<%e% />%o% Else o =%op_s%<%e%>%o% } Else If (i > 0) { StringRight, t, s, StrLen(s) - InStr(s, "%op_sa% Else s =%op_s%<%e%>%op_sa% Loop, % i - 1 If InStr(op, "fused ") r =<%e% />%r% Else r =<%e%>%r% } } Else { i++ StringGetPos, t, s, <%e%%A_Space%, L%i% StringLeft, t1, s, t r =%r%%t1% StringTrimLeft, s, s, t StringLeft, t, s, InStr(s, ">") + 1 If InStr(t, "/>") t := InStr(s, "/>") + StrLen("/>") Else t := StrLen(s) - InStr(s, "", 1) + 1 - StrLen("") StringRight, t1, s, t o =%t1%%o% StringTrimRight, s, s, t } t := "" Loop, % A_Index - 2 t =%t%%op_ind% StringReplace, r, r, `r`n%t%`r`n, `r`n, 1 StringReplace, r, r, <%e%%A_Space%>, <%e%>, 1 StringReplace, s, s, <%e%%A_Space%>, <%e%>, 1 StringReplace, o, o, <%e%%A_Space%>, <%e%>, 1 } StringReplace, type, type, [", [' StringReplace, type, type, "], '] If !type or type = "string" { StringLeft, t, s, InStr(s, ">") If (data = "" and (t = "<" . e . ">" or t = "<" . e . " />")) { s := "" } Else { r =%r%%t% StringTrimLeft, s, s, % t StringRight, t, s, StrLen(s) - InStr(s, "", 1) + 1 o =%t%%o% StringTrimRight, s, s, StrLen(s) - InStr(s, "", 1) + 1 s =%data% } } Else If (InStr(type, "processor") or InStr(type, "attribute")) and (!InStr(type, "['") and !InStr(type, "']")) error := true If InStr(type, "attribute") { StringReplace, type, type, attribute[' StringReplace, type, type, '] StringRight, t, s, StrLen(s) - InStr(s, ">") o =%t%%o% StringTrimRight, s, s, StrLen(s) - InStr(s, ">") If InStr(s, type . "=") { StringRight, t, s, StrLen(s) - (InStr(s, type) + StrLen(type . "=")) StringLeft, t, t, InStr(t, """") - 1 StringReplace, s, s, %type%="%t%", %type%="%data%" } Else StringReplace, s, s, >, %A_Space%%type%="%data%"> } Else If InStr(type, "processor") { StringReplace, type, type, processor[' StringReplace, type, type, '] If !p p = Else If InStr(p, type . "=") { StringRight, t, p, StrLen(p) - (InStr(p, type) + StrLen(type . "=")) StringLeft, t, t, InStr(t, """") - 1 StringReplace, p, p, type . "=""" . t . """", % type . "=""" . data . """" } Else StringReplace, p, p, ?>, %A_Space%%type%="%data%"?> } StringLeft, t, r, 2 IfEqual, t, `r`n, StringTrimLeft, r, r, 2 AutoTrim, %xAT% StringCaseSense, %xSC% SetBatchLines, %xBL% If error Return, true FileDelete, %file% s =%p%%r%%s%%o% StringReplace, s, s, `r`n`r`n, `r`n, 1 FileAppend, %s%, %file% IfNotEqual, ErrorLevel, 0, Return, true Return, false } Exit