As I wrote previously in “Writing With Pleasure Using Markdown and Pandoc”, I use Markdown a lot for writing. I don’t use it just for writing articles, but also for writing outlines and making notes. If I draft it using plain text, then I usually use Markdown as the format.

Imagine my surprise this morning when I tried to search for an outline I’d drafted of a conference talk and couldn’t find it. I couldn’t even find it by file name. Panic!

The Symptoms

Today, I was flipping through some paper notes, trying to clean them up by digitizing what I needed to save, adding tasks for things I needed to do with them, then shredding them for recycling. I came across handwritten notes for a conference talk I plan to record soon. I felt certain that I’d already transcribed the notes into a plain text file—in Markdown format, of course—so I popped open Spotlight to search for the text in my head along with the operator kind:markdown, meaning “search in Markdown files”.

Spotlight found nothing. Weird.

I looked around my computer’s file system for where I thought I filed the outline document and I found it in a file called 60-Minute Talk Sketch.markdown. I opened it and found the exact line of text I’d searched for with Spotlight. Why didn’t Spotlight find it? I tried one more thing.

I love Alfred for moving around my computer’s file system. I won’t even try to write about how much time it saves me. I hate using other people’s computers for more than a few minutes unless they have Alfred installed. I sometimes worry that it slowly makes me increasingly unable to use a typical Mac. I digress.

Since Alfred uses data from Spotlight to find files, I opened Alfred to search for my conference talk outline. I couldn’t even find the file by name! Super weird.

I asked Alfred to find some other files for me… it found them without trouble. Just not Markdown files.

Ugh. I guess I have to “fix” something….

Spotlight and Markdown

Fortunately, others have encountered this problem before I, and have written about how they solved it. It appears that, out of the box, Mac OS X has no idea what a Markdown file is, so we have to tell it. This makes sense to me, so while it annoys me, and least it doesn’t surprise me. We need to tell Spotlight about the Markdown file format and in order to be able to search inside Markdown files, we can tell Spotlight, “Treat them like Rich Text files.” That sounds reasonable to me.

The Steps I Used to Solve the Problem

An overview of the steps:

  1. Download and install an “importer” that instructs Mac OS X to index Markdown files as though they were just another kind of Rich Text.
  2. Ask Spotlight to reindex everything.
  3. Wait several minutes and try again.

Now, the details.

The Detailed Steps

Read “A Yosemite Markdown Spotlight Importer” for details.

  1. Click here to download the importer.
  2. Uncompress the importer.
  3. Copy the file Markdown.mdimporter to /Library/Spotlight.
  4. Open Terminal and tell Spotlight to reindex the entire local hard disk. sudo mdutil -E /
  5. Check that Spotlight is using the new importer. mdimport -L should match at least one line of output, showing the location to which you copied Markdown.mdimporter.
  6. Wait several minutes. I’ll have a tea sounds nice.1
2016-01-26 12:01:21.177 mdimport[27566:3379462] Paths: id(501) (
    [...some irrelevant importers...]
    "/Library/Spotlight/Markdown.mdimporter",
    [...and so on...]
)

Some instructions tell you to copy the importer file to $HOME/Library/Spotlight, meaning at the scope of the current logged-in user. Since some people reported that that didn’t work for them, and I wasn’t in the mood to mess around, I just copied it to /Library/Spotlight, meaning at the scope of all users. If you want to experiment with copying this to $HOME/Library/Spotlight, then feel free. It might also work.

This worked for me. I hope it helps you.

Epilogue

Someone asked about this in an Apple discussion board thread from 2008, but there seems no way to tell that person about the solution. This makes me sad.

References

Hilton Lipschitz, “A Simple Markdown Spotlight Importer”.

Hilton Lipschitz, “A Yosemite Markdown Spotlight Importer”.

Stack Overflow, “How can I make spotlight index markdown files?”. More details on the solution, how it works, and alternative approaches.

Anthony Craig, “How to Force Spotlight to Index Markdown Files in El Capitan”.

Brett Terpstra, “Fixing Spotlight indexing of Markdown content”. All roads appear to lead to this article.


  1. If you don’t get the reference, then I can’t help you.↩︎