Fun with plain-text notes (searching Obsidian tasks)
Update: I realized after reviewing the search docs that you can use Obsidian's standard search for this. Just enter: task:{query}
. My thing below is still a touch faster for me, but I might not have bothered to make it if I'd RTFM! I was focused only on the Obsidian Tasks docs. Oh well!
As I've mentioned too many times, I use Obsidian for both my work and personal notes, each in their own vault. At work I also use Obsidian for task management with the Obsidian Tasks community plugin, which seems to be the de facto standard. (For personal tasks, I use Things.)
One missing feature in Tasks is the ability to quickly search across all the tasks in your vault. I think it's on their roadmap. I've been working around it by having this snippet handy:
not done
description regex matches /{SEARCH QUERY HERE}/i
sort by priority
That displays a list of the results. But it's clunky, and I'd really like to do the sort of search we're all accustomed to now: a big list of stuff that progressively filters via fuzzy matching as you type.
Fortunately, because the notes are just Markdown files on disk, and the tasks are just lines in those files, it's fairly straightforward to roll my own while I wait.
My starting point for these sorts of things is Alfred, another favorite app that I've mentioned several times. Fuzzy search is Alfred's bread and butter, and I'm pretty fast now at cobbling together custom workflows, typically using Python scripts to fetch or process data and feed it back to Alfred. I can build a simple workflow in under five minutes. (I'm no genius. Just saying, it gets easy once you've done it a few times.)
I'm using ripgrep to find all the task lines in my notes. I chose ripgrep because it's blazing fast at this. In my case, it searches my 6600 files in 120 milliseconds. Here's an example search, using JSON output so Python can easily parse it:
rg "^\s*- \[ \] " --type md --json
Then in Python, I parse the JSON, find all the matches, strip each task line to remove leading whitespace (the tasks are often heavily indented inside a bulleted list in the file), and package the results into the JSON format Alfred expects for its List Filter. The script prints the JSON dump of that data structure for Alfred to read, and then Alfred gives me a fuzzy-searchable list. Halfway there!
When I choose a task to open, Alfred sends it back to the script with an --open
flag. The script then builds an Advanced URI that points to correct Obsidian note and line within it. The script opens that URL, and bam! I find myself in Obsidian with the cursor on the task I chose.
Okay, when I write it all out, I admit it sounds a little convoluted. I'm already used to all this stuff, and I've written scripts like this several times before, so for me it's pretty straightforward. 😆
A better solution is doing this in an Obsidian plugin. I'm getting faster at writing those, too, so that's probably next.
The point is, when your notes are just plain-text files on disk, it opens a huge amount of room to play around with searching, processing, backups, etc. And that's what this is, really — play. Although every once in a while, one of these little side quests sticks and is a legit help in the long run.
Time to work. Cheers!