Skip to content

Instantly share code, notes, and snippets.

@breiter
Last active October 30, 2023 10:24
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save breiter/1d3d7db645fd4a6e5c57 to your computer and use it in GitHub Desktop.
Save breiter/1d3d7db645fd4a6e5c57 to your computer and use it in GitHub Desktop.
Enable Spotlight indexing of Markdown in ~~El Capitan~~ Monterey without disabling SIP
--- /System/Library/Spotlight/RichText.mdimporter/Contents/Info.plist 2022-02-26 09:05:07.000000000 +0200
+++ /Library/Spotlight/Markdown.mdimporter/Contents/Info.plist 2022-03-22 21:01:30.000000000 +0200
@@ -13,27 +13,20 @@
<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>net.daringfireball.markdown</string>
</array>
</dict>
</array>
<key>CFBundleExecutable</key>
- <string>RichText</string>
+ <string>Markdown</string>
<key>CFBundleGetInfoString</key>
<string>1.0, Copyright (c) 2004-2019 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>
@breiter
Copy link
Author

breiter commented Nov 23, 2015

  • Create a copy of the system RichText.mdimporter
  • patch to set it up to only index markdown
  • rename it to Markdown.mdimporter
  • Copy into /Library/Spotlight
  • Tell spotlight to start indexing with it
cp -r /System/Library/Spotlight/RichText.mdimporter .
patch -p2 RichText.mdimporter/Contents/Info.plist < Markdown.mdimporter.patch
mv RichText.mdimporter Markdown.mdimporter
sudo cp -R Markdown.mdimporter /Library/Spotlight
mdimport -r /Library/Spotlight/Markdown.mdimporter

@adib
Copy link

adib commented Dec 2, 2015

You need to rename the patch file to "Markdown.mdimporter.patch". Notice the missing k.

@jassey
Copy link

jassey commented Sep 21, 2017

cool :)

How to rebuild the Spotlight index on your Mac:
https://support.apple.com/en-us/HT201716

@leonroy
Copy link

leonroy commented Mar 22, 2022

things have changed slightly with Monterey, new patch:

--- RichText.mdimporter/Contents/Info.plist	2022-03-22 18:33:28.000000000 +0000
+++ Markdown.mdimporter/Contents/Info.plist	2022-03-22 18:35:51.000000000 +0000
@@ -13,14 +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>net.daringfireball.markdown</string>
 			</array>
 		</dict>
 	</array>
@@ -29,11 +22,11 @@
 	<key>CFBundleGetInfoString</key>
 	<string>1.0, Copyright (c) 2004-2019 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>

@breiter
Copy link
Author

breiter commented Mar 22, 2022

sudo cp -r /System/Library/Spotlight/Richtext.mdimporter /Libary/Spotlight/Markdown.mdimporter

--- /System/Library/Spotlight/RichText.mdimporter/Contents/Info.plist	2022-02-26 09:05:07.000000000 +0200
+++ /Library/Spotlight/Markdown.mdimporter/Contents/Info.plist	2022-03-22 21:01:30.000000000 +0200
@@ -13,27 +13,20 @@
 			<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>net.daringfireball.markdown</string>
 			</array>
 		</dict>
 	</array>
 	<key>CFBundleExecutable</key>
-	<string>RichText</string>
+	<string>Markdown</string>
 	<key>CFBundleGetInfoString</key>
 	<string>1.0, Copyright (c) 2004-2019 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>

@leonroy
Copy link

leonroy commented Oct 30, 2023

anyone finding this isn't needed now with Ventura and Sonoma?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment