External linking for nvALT notes 2: nvWikiLinker
Continuing yesterday’s foray into linking nvALT notes to any application, here’s the universal script that makes any text linkable to nvALT without extra urls.
It’s best run as a Service, and one is included in the download. If you add a hotkey to it in System Preferences, you’ll be able to select text you’ve written in any app, hit your hotkey and open a related note. If it’s the first time you’ve used it on that text, it will create the initial note for you.
It works using wiki-style linking, both with
[[square bracket style]] and
WikiLink style, where the beginning of each word is capitalized and there are no spaces. If a square bracket link exists in the text, it takes priority over any WikiWords found, and only one note can be linked with the selected text (the first title it finds is what it will link to).
When you run the Service/script, it looks for the wiki words in the text passed to it (as a script you want to pass the input to STDIN; the Service does this automatically with any selection). If one is found, it checks your notes folder for the closest matching note with a fairly low threshold. If nothing (almost) perfect is found (there’s a little leeway), it will create a new note based on the wiki word and add the entire selected text to it.
Once you’ve created the note for the text, you can run the service on any selection that contains that wiki word and the original note will be opened.
Say, in a mind map you had a topic node that was just [[Project X research]]. Selecting that text and running the Service would create a new note called “Project X research” and open it in nvALT. You’d add your notes for that node to nvALT and then go back to your mind map. Next time you select that text and run it, your notes pop back up.
You can also use a larger block of text:
These are the notes for Project X. My ProjectXResearch has shown that there is no basis for the claim that “[any particular nationality, socio-economic or social behavior group] do it better.”
If you select that text for the first time and run the Service, the “Project X Research” note will be created with the text in it. Next time you run it, it will open the original note and you can add/edit the contents. From that point on, you just have to select the word ProjectXResearch, and you can use that link again in any other application.
For both the script and the Service, there is only one line to edit. It’s right after the intro credits, and simply points to your notes folder where you keep plain text versions of your nvALT notes (not database storage). If you’re running the System Service, add a hotkey for it and save yourself some time.
It’s possible to use the script with other apps which can pass plain text to it. Alfred and LaunchBar should both be able to do it, but it might take some adjustment. Personally, I’m quite happy with running Services, so I haven’t fully explored the possibilities.
Also note that this system could easily be modified to work with any plain text notes system. If you’d rather open your files in a text editor or other notes application which reads files on disk, just adjust the
osascript commands in the script. A little regex work can adjust the way it detects wiki links as well.
The code is up on Github, including the Service. Download the bunch and install the “.workflow” file in
[HOME]/Library/Services. It will show up immediately in the Services menu accessible when you have text selected and right click on it (or pull down the application menu in the menu bar).
This is a work in progress, you may find that it chokes on some characters or doesn’t detect a note that should already exist. Please report these as an issue on the repo so I can try to figure out how to improve it. I think this could be a handy tool, and I’d like to polish it up. Also, because I don’t think I have enough to occupy my time1.
If you’ve ever been curious as to whether or not I have psychological issues, I present Exhibit A, a.k.a. “what happened to 40 minutes of my time yesterday.” The script wasn’t even finished yet. I had to run a regex cleanup just to be able to edit it. I scare myself.
I would, however, like to point out that I resisted creating a “humorous” header for this post. I didn’t even open Acorn up. Self control. ↩