Back in my Windows days, I used Todoist as my task manager. Todoist has many great qualities, but when I was brainstorming and project planning, I wanted the flexibility that a text editor could give me. I made this script to transform a taskpaper-type syntax into a file that Todoist could use (it used to be that you could import from a text file using a specific syntax. I don’t know if that’s possible anymore.)
Breaking down the script:
- Lines 3-5 … I’ve covered
#singleinstance force
andSetTitleMatchMode
before. I use them in nearly every script. - Line 7 …
WinActivate
activates the window with “Notepad++” somewhere in the title. - Line 8 … pauses the script until Notepad++ is the foreground window. Since I’m sending generic copy/paste commands, I wanted to make sure I’m doing those on the right window.
- Lines 10-12 … select and copy all.
- Line 14 … take the contents of the clipboard and assign it to the variable
SL_Input
. - Line 15 … create a variable with the current timestamp, down to the second.
- Line 17 … In taskpaper, a project is defined by a colon at the end of the line. I use this variable to test whether the line is a project or not.
- Lines 19-26 … The heart of the script depends on a series of text replacements. Here I define the text elements the script looks for.
- Lines 28-34 … these are the text elements that get substituted for their related ones above. They’re built on the syntax that Todoist used to use for template import.
- Line 37 … replaces all carriage returns with that star-like character. The text parser in line 48 depends on a single character, and it could not recognize a line break. So I replace all line breaks (
r
n) with this character. - Line 38-45 … replace the text elements, changing the bulleted list into the ellipsis-delineated list. They’re done in reverse order because of the way the text replacement function works: a bullet with 8 spaces could be recognized as a bullet with 4 spaces and 4 empty spaces in front of it. I never figured out how to make the tolerance tighter without totally ruining the script.
- Line 48 … this loop is how I write the new file in the proper format. the
parse
command tells the loop to cycle through the text insl_input
, breaking at every instance of the star character. - Line 50 … the
StringRight
command takes the first character from the right hand side of the string and puts it in the variableProject_Test
. This tests whether the line defines a project. Note that if there’s a space at the end of the line, it will take that and miss a project definition. - Line 53 … if the line defines a project, it gets appended to the file with Markdown bold syntax. Its my preference to have project titles bolded, and Todoist parses some Markdown, so I used it. I explained the
FileAppend
command in the script above - Line 57 … if the line is not a project, it gets appended to the file as is.
- Line 59 … adds a return between lines.
A few other notes:
- I would sometimes save multiple files during the course of a day and then import them all at once. By having the filename be the timestamp down to the second, I could be confident that I would overwrite one file with another. I could have done it down to the minute, but then what fun would that be?
- I have another similar script that lets me clean up Kindle notes. Use case: go to the Kindle notes page on the web, copy and paste notes into a text editor, run the script to remove all the excess formatting .
- I have another one that cleans up an email list for meeting notes. Use case was to hit reply-all to a meeting invite and copy the single line of multiple email addresses. The script would then turn that into a bulleted list with one name per line and put it on the clipboard. I could then paste a nicely formatted list of everyone on the invite into my notes. Yes, OneNote and the clipper will do that also, but where’s the fun in that?
- I had a pair that would remove star bullets and replace them with dashes. You know, because I’m civilized.
- I had another pair that would remove bullets and replace bullets. Used this a lot less than I thought I would.
; Turn bulleted list into todoist
#SingleInstance force
settitlematchmode, 2
Winactivate, Notepad++
winwaitactive, Notepad++
Send ^a
sleep 10
Send ^c
SL_input = %clipboard%
FormatTime, TimeString,,yyyy-MM-dd_HH-mm-ss
Project_Char := ":"
SL_LCom1 := "//"
SL_LCom2 :="--"
SL_L0 := ""
SL_L1 := "- "
SL_L2 := " - "
SL_L3 := " - "
SL_L4 := " - "
SL_L5 := " - "
SL_RCom :="[[NOTE]]: "
SL_R0 :=
SL_R1 := "..."
SL_R2 := "......"
SL_R3 := "........."
SL_R4 := "............"
SL_R5 := "..............."
StringReplace, sl_input, sl_input, `r`n , ¤, All
StringReplace, SL_input, SL_input, %SL_LCom1%, %SL_RCom%, All
StringReplace, SL_input, SL_input, %SL_LCom2%, %SL_RCom%, All
StringReplace, SL_input, SL_input, %SL_L5%, %SL_R5%, All
StringReplace, SL_input, SL_input, %SL_L4%, %SL_R4%, All
StringReplace, SL_input, SL_input, %SL_L3%, %SL_R3%, All
StringReplace, SL_input, SL_input, %SL_L2%, %SL_R2%, All
StringReplace, SL_input, SL_input, %SL_L1%, %SL_R1%, All
StringReplace, SL_input, SL_input, %SL_L0%, %SL_R0%, All
Loop, parse, SL_input, ¤,
{
StringRight, Project_Test, A_Loopfield, 1
If Project_Test = %Project_Char%
{
FileAppend, **%A_Loopfield%**, C:\[PATH]\%TimeString%.txt
}
else
{
FileAppend, %A_Loopfield%, C:\[PATH]\%TimeString%.txt
}
FileAppend, `r, C:\[PATH]\%TimeString%.txt
}
ExitApp