Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.4: Spotlight's rules for indexing plain text files' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Spotlight's rules for indexing plain text files
Authored by: Safar on May 13, '05 11:57:59AM

does not work for me :
$ SetFile -t TEXT ~/test.php
$ GetFileInfo -t ~/test.php
"TEXT"
$ mdimport -d1 ~/test.php
2005-05-13 17:56:40.995 mdimport[2806] Import '/Users/mic/test.php' type 'public.php-script' no mdimporter



[ Reply to This | # ]
10.4: Spotlight's rules for indexing plain text files
Authored by: atverd on May 13, '05 12:36:47PM

This is an another case. The file's type actually recognized as php-script through it's extension and obviously the TEXT tag got overruled. The hint works only for files with unrecognized types, those which reported as dyn.* by mdimport.



[ Reply to This | # ]
10.4: Spotlight's rules for indexing plain text files
Authored by: atverd on May 13, '05 01:30:16PM

As I said before even though this is a different kind of issue I think I know how to fix it. We have to tell spotlight to treat scripts like plain text files. Edit file /System/Library/Spotlight/RichText.mdimporter/Contents/Info.plist, find this section and add public.php-script as shown below:

<dict>
<key>CFBundleTypeRole</key>
<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>public.php-script</string>
</array>
</dict>

After saving the file run mdimport -d1 on some php script again and this time it should import it as a plain text. Worked for me.



[ Reply to This | # ]
10.4: Spotlight's rules for indexing plain text files
Authored by: Safar on May 13, '05 02:23:08PM

THANK YOU ! This is great, and should definitely have a hint of its own. I saw lots of places on the web where people try to achieve this sort of behavior.

I did exactly what you said, and then ran mdimport -f ~/webserver/ on my webserver to force spotlight to reindex my webserver, where all my php files rest.

Now i can search by content my php files.

I would just like to precise how you can get the type for a given extension (eg 'public.php-script' for php files). Run mdimport -d1 on a file with that extension , and observe the output.



[ Reply to This | # ]
10.4: Spotlight's rules for indexing plain text files
Authored by: jmichaelson on May 13, '05 07:40:43PM

I did a similar approach (I thought about posting this hint, but obviously I was beaten to the punch), but used the source code importer in /Library/Spotlight. All you need to do is add the file extension to the info.plist entry under CFBundleDocumentTypes > 0 > LSItemContentTypes. Just use the New Sibling button and under value, type the extension (I added .cgi, .pl, and .pm entries). Now Spotlight sees and indexes all my Perl stuff. You can add any other type of plain text extension, which makes this much more effective than the original hint here.



[ Reply to This | # ]
10.4: Spotlight's rules for indexing plain text files
Authored by: atverd on May 13, '05 08:25:23PM

I actually tried the source code importer first, but it looks like it's made specifically for C/C++/ Objective C/C++ and I'm not sure how it's going to behave with other languages. I think the plain-text importer is safer.



[ Reply to This | # ]