20

I typically use the .markdown or .md extension for markdown documents. Unfortunately spotlight refuses to index them unless they have the .txt file extension.

I've seen a possible solution involving editing Info.plist files on the textmate blog. Is there a better way?

Update: I just discovered QuickLook generator for Markdown files which adds spotlight support and nice HTML quicklook previews. It works a treat!

mloughran
  • 11,415
  • 7
  • 28
  • 22
  • 4
    This doesn't seem "programming related", but I sure am glad the "watchdogs" didn't shoot you down! I needed this info. +1. – Charlie Flowers Apr 09 '09 at 16:03
  • The current QL gen project is found here: https://github.com/toland/qlmarkdown . The old one (linked to above) did not like XCode 7... – om01 Sep 09 '17 at 17:38

5 Answers5

6

You can do this without disabling SIP by creating a copy of the system RichText.mdimporter, modifying its Info.plist and saving it in /Library/Spotlight.

cp -r /System/Library/Spotlight/RichText.mdimporter .
patch -p2 RichText.mdimporter/Contents/Info.plist < Markdown.patch
mv RichText.mdimporter Markdown.mdimporter
sudo cp -R Markdown.mdimporter /Library/Spotlight
mdimport -r /Library/Spotlight/Markdown.mdimporter

Markdown.patch

diff -ru RichText.mdimporter/Contents/Info.plist Markdown.mdimporter/Contents/Info.plist
--- RichText.mdimporter/Contents/Info.plist 2015-11-23 16:14:12.000000000 +0200
+++ Markdown.mdimporter/Contents/Info.plist 2015-11-23 16:10:03.000000000 +0200
@@ -13,15 +13,7 @@
            <string>MDImporter</string>
            <key>LSItemContentTypes</key>
            <array>
-               <string>public.rtf</string>
-               <string>public.html</string>
-               <string>public.xml</string>
-               <string>public.plain-text</string>
-               <string>com.apple.traditional-mac-plain-text</string>
-               <string>com.apple.rtfd</string>
-               <string>com.apple.webarchive</string>
-               <string>org.oasis-open.opendocument.text</string>
-               <string>org.openxmlformats.wordprocessingml.document</string>
+               <string>net.daringfireball.markdown</string>
            </array>
        </dict>
    </array>
@@ -30,11 +22,11 @@
    <key>CFBundleGetInfoString</key>
    <string>1.0, Copyright (c) 2004-2010 Apple Inc.</string>
    <key>CFBundleIdentifier</key>
-   <string>com.apple.MDImporter.RichText</string>
+   <string>com.apple.MDImporter.Markdown</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
-   <string>Rich Text Sniffer</string>
+   <string>Markdown Sniffer</string>
    <key>CFBundleShortVersionString</key>
    <string>6.9</string>
    <key>CFBundleSupportedPlatforms</key>
SimplGy
  • 20,079
  • 15
  • 107
  • 144
Brian Reiter
  • 1,339
  • 1
  • 10
  • 16
  • All you really need to do is copy rich text and add `net.daringfireball.markdown`, but either way, this answer works like a charm. Thanks! – SimplGy Jan 26 '17 at 21:34
  • @SimplGy Yes that worked for me on High Sierra. `cp -r /System/Library/Spotlight/RichText.mdimporter .`, then add that line, then `sudo cp -R RichText.mdimporter /Library/Spotlight` and `mdimport -r /Library/Spotlight/RichText.mdimporter` – David Aldridge Mar 06 '18 at 10:43
4

You'll have to write a Spotlight importer. There's an Xcode project template that will set the basic stuff up for you and get you started; I think there's also a developer example.

Your importer will need a UTExportedTypeDeclarations section in its Info.plist that describes a Uniform Type Identifier for markdown files with you path extension. Then it's just a matter of having your importer pass Spotlight the appropriate data for a markdown file.

Chris Hanson
  • 54,380
  • 8
  • 73
  • 102
2

The following works for Mac OS X 10.11 El Capitan:

As we cannot edit system files in El Capitan, we have to temporary disable SIP (System Integrity Protection) (for full details have a look at this Lifehacker article).

  • Reboot your Mac into Recovery Mode by restarting your computer and holding down command + R until the Apple logo appears on your screen
  • Click Utilities > Terminal
  • In the Terminal window, type in csrutil disable and press Enter
  • Restart your Mac

Now we can edit the file located at /System/Library/Spotlight/RichText.mdimporter/Contents/Info.plist:

  • sudo open -a TextEdit /System/Library/Spotlight/RichText.mdimporter/Contents/Info.plist
  • Add <string>net.daringfireball.markdown</string> under LSItemContentTypes (for more infos see original post)

When you are finished you may want to reindex the folders containing the Markdown files, have a look at this article for that: Spotlight: How to re-index folders or volumes. And don’t forget to turn SIP back on by repeating the first part and running csrutil enable.

Pwdr
  • 3,712
  • 4
  • 28
  • 38
0

This gist explains how to modify the RichText.mdimporter to import source and markdown files.

sal
  • 23,373
  • 15
  • 66
  • 85
-5

You could write a Importer, but there's an easier way. Markdown is just text, which Spotlight handles. If you give your markdown files the extension ".txt", Spotlight will pick them up.

In my case, I just named mine all to end with ".mdwn.txt" and taught emacs' markdown-mode to activate for files matching this extension.

bendin
  • 9,424
  • 1
  • 39
  • 37