Quick insertion of tags with type-ahead search (using Keyboard Maestro)
Use case: If you have a serious amount of tags you will might get in trouble figuring out which ones already exist and how you spelled them exactly (caps? CamelCase? singular?). Wouldn't it be nice to have an (automatically updated) list of all
#tags you use in your Zettelkasten and could easily insert them everywhere.
Keyboard Maestro to the rescue: This workflow requires two macros. One will keep an eye on your tags an occasionally collect them, the other uses the collection for a convenient search bar.
The Tag Collector Macro
This macro uses a piped series of small shell commands to extract all the tags from the files in the archive folder.
A short rundown:
egrep -ohws "\B#[a-z][A-za-z0-9_-ÄÖÜäöüß]+" *
This part does the searching. It searches for everything that starts with a
[a-z] matches a lower case letter. Why? I insert this step to exclude some false matches. In my archive I have a lot of HEX color codes like
#F0F0F0 - I always write those with uppercase letters and all my tags start lower case. I also have quite an amount of
#1, #2, #n's appearing in my notes which are also not tags. This little restrictions sorts out an resonable amount of "false tags". If you have other tagging habits, simply remove the
[A-za-z0-9_-ÄÖÜäöüß]+ defines all the characters that can occur in a tag. In my case: all letters, numbers and a few special characters an umlauts. Add yours to this collection as needed.
The second part
sed /^[^#]/d| sort | uniq removes duplicates, sorts the list, and does a little additional clean up.
Keyboard Maestro saves result in a variable for later use. The macro needs a trigger to update the list and include new tags. Keyboard Maestro provides a lot of trigger options. For my needs "At login" is frequent enough. But you might also consider "At system wake" or "Periodically" or at fixed times.
The Tag Selector Macro
This does not need much explanation. It is basically the same logic as in the note-link-macro. Make sure you use the same variable name as in the collector macro in the first step.
If you give this macro a global shortcut, you can access your tags everywhere on your system.
A screenshot of the result, that is: the tagbar in action:
Please note: In my case, I still have a few false positives left: non-tags appearing in this list. As long as it is a small number, I don't mind them. But of course you could optimize this further.
It looks like you're new here. If you want to get involved, click one of these buttons!