Back to top

Some Scripts for Native Tagging of Markdown Files

One thing I like about Markdown is the way the files are just plain-text files, that can be opened and read in different programs and contexts. As much as I can, I try not to lock down my content, or workflows, into specific apps. But I still want to use nice apps! So sometimes I have to jump through a few hoops to make things interoperate. I’ll go into more detail on my workflows later — but I thought I’d share some scripts I use in one piece of the puzzle.

Here's the link to the scripts. I started with a script from this repo, which I then spent a good amount of time editing (with the help of an LLM). So feel free to come with suggestions for how they can be improved!

First, here’s what they do:

What I want is to be able to tag things in the different programs I use, and then automatically apply native Finder/Files tags to the files themselves. If I want to make three tags called “Bass guitar”, “Music” and “Effect pedals”, I would write #Bass guitar# #Music #Effect pedals#. (Notice how the multi-word ones also end with a #.)

The scripts come in three different flavours:

  • front_matter-tags.rb: This only is meant to only capture tags added in the front matter. It looks for the first line that starts with “tags:”, and then it adds the #tags in #that line#. This one also works in Bike documents!
  • ulysses-keywords.rb: When you add a keyword in Ulysses, it simply adds them as hashtags on the last line of the document. 1 This script adds them, and just them, as native tags.
  • md-tags.rb: This scans the entire file and adds every tag!
If I want to tag a Bike document, I'll just add a 'comment' line like this at the top.
And here's some front matter in NotePlan.
And these are the keywords in Ulysses. And all of these gets added as native tags!

How I run them

The original repo created some sort of launch agent to run the scripts — but I never got that to work. So I use Hazel. Whenever a file is added or modified in a folder, I run a script like this:

/usr/bin/env ruby /path/to/scripts/ulysses_keywords.rb
So, it's "Kind is Document" and "Date Created/Date Last Modified is after Date Last Matched", and then "Run schell script" and then the script above.

All the scripts start with “sleep 5”, which is a five-second wait. I found that this increased the reliability with Hazel — but it might not be necessary in all contexts. Also, I think it will read over every file every time it runs! (For better or for worse.)

Hopefully, someone else might find this useful. It should be pretty easy to adapt them to your needs, and also improve them!


  1. I use Ulysses with native .md files through external folders. ↩︎