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

10.4: Use Spotlight to globally index any text file Apps
Tiger only hintI write a lot of perl code using BBEdit, and wanted Spotlight to index my perl files. To do this, a simple modification of the the RichText.mdimporter is needed. First find the type (according to Spotlight) of the files you want indexed using this command in the Terminal:
mdimport -n -d1 theFileName.ext
which outputs something like:
Import 'theFileName.ext' type 'someSpotlightType' no mdimporter
Now take that file type (someSpotlightType) and add it to the Info.plist file located at /System -> Library -> Spotlight -> RichText.mdimporter -> Contents -> Info.plist. Add it in the array for LSItemContentTypes:
<key>CFBundleDocumentTypes</key>
  <array>
    <dict>
     <key>CFBundleTypeRole</key>
          <string>MDImporter</string>
     <key>LSItemContentTypes</key>
     <array>
          <string>someSpotlighType</string>
          <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>
     </array>
   </dict>
  </array>
Now go back to the Terminal and import the files in question (mdimport /PathToFiles/ToImport), or you can even re-import everything (sudo mdimport /). To see what is going on, add the -d1 switch to the mdimport command. Now Spotlight will be able to handle the new file types -- add as many as you like. Of course, you want to make sure that you only add files that are in fact text files!
    •    
  • Currently 3.17 / 5
  You rated: 5 / 5 (6 votes cast)
 
[30,646 views]  

10.4: Use Spotlight to globally index any text file | 13 comments | Create New Account
Click here to return to the '10.4: Use Spotlight to globally index any text file' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use Spotlight to index any text file - Globally
Authored by: jcburns on Jun 03, '05 10:25:28AM
Great idea.. to keep things orderly, I added

<string>public.perl-script</string>
<string>public.python-script</string>
<string>public.ruby-script</string>
<string>public.php-script</string>
...not to the Rich Text importer, but to the SourceCode.mdimporter plist (located in my /Library/Spotlight folder, installed with Developer Tools) as mentioned in this MacOSXHints article.

[ Reply to This | # ]
Use Spotlight to index any text file - Globally
Authored by: raphaeld on Jun 03, '05 11:05:58AM

I wrote a quick Xcode/AppleScript app for me to make a quck note and save it as a text file (I'm using AppleScripts write command) in a folder with the intention of using Spotlight to retrieve the info in the future. Unfortunately, for reasons unknown to me, Spotlight doesn't index them. Would your hint solve this problem? If so, how would I modify it for these files (I'm saving them as .txt files) that I thought would already be indexed?

Thanks



[ Reply to This | # ]
Use Spotlight to index any text file - Globally
Authored by: romulis on Jun 03, '05 11:20:06AM

Great tip, thanks!

OK, so I write perl, php and ksh scripts. perl and php work just fine, but ksh seems to be completely unknown to OSX :-(

% mdls my.ksh
...
kMDItemContentType             = "dyn.ah62d4rv4ge80065k"
...

I discovered /System/Library/CoreServices/CoreTypes.bundle/Contents/Info.plist which seems to define file types based on their filename extensions, but adding ksh next to the sh entry had no effect (even after a reboot).

atverd's tip almost helps (at least a ksh script can be treated as a dumb text file), but I would have to set the type of every ksh manually.

Does anyone know how to register new filetypes with spotlight? (perl, ruby, php etc are already defined, just not included in indexing. ksh on the other hand is completly unknown)

Thanks in advance,

Steve



[ Reply to This | # ]
You have to create this UTI.
Authored by: atverd on Jun 03, '05 01:04:18PM

If CoreTypes doesn't recognize some type you have to create the definition yourself. In fact you may modify Info.plist of _any_ Cocoa application and it will work just fine. But this is definitely not a clean way to solve the problem in general, so I've created a Cocoa bundle which has the only purpose - export my UTIs to system. You may download it and unpack to your Application folder:

http://www.lexa.ru/andyt/MyUTIs.bundle.zip

After that you'll have to edit it's Info.plist file and create a dictionary for each type you want to identify. The type must be unknown to system (dyn.*** kind in mdimport output)! In this example I've created two - one for kshell and one fake for bsh (you may remove it). After that just add that com.kornshell.ksh-script as described in this hint and mdimport should pick all your .ksh files from here based on defined file extensions.

The good thing about this bundle is that you can move it between systems and upgrades and it will define all your types automatically.



[ Reply to This | # ]
You have to create this UTI.
Authored by: rotaiv on Jun 03, '05 03:36:57PM
I downloaded your bundle and modified the info.plist to include VBS scripts files I have backed up from my XP Desktop. See below for the contents of my updated info.plist file.

Once that was done, I went into the folder with my .VBS files and ran, "mdimport -d1 ." The files are still showing up as having no mdimporter. Is there something else I need to do?

Any help you can give would be appreciated :)


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>CFBundleDevelopmentRegion</key>
        <string>English</string>
        <key>CFBundleExecutable</key>
        <string>MyUTIs</string>
        <key>CFBundleIdentifier</key>
        <string>com.biapo.utis</string>
        <key>CFBundleInfoDictionaryVersion</key>
        <string>6.0</string>
        <key>CFBundlePackageType</key>
        <string>BNDL</string>
        <key>CFBundleSignature</key>
        <string>????</string>
        <key>CFBundleVersion</key>
        <string>1.0</string>
        <key>NSPrincipalClass</key>
        <string>NSApplication</string>
        <key>UTExportedTypeDeclarations</key>
        <array>
                <dict>
                        <key>UTTypeConformsTo</key>
                        <string>public.plain-text</string>
                        <key>UTTypeIdentifier</key>
                        <string>com.biapo.vbs-script</string>
                        <key>UTTypeTagSpecification</key>
                        <dict>
                                <key>public.filename-extension</key>
                                <array>
                                        <string>vbs</string>
                                </array>
                        </dict>
                </dict>
        </array>
</dict>
</plist>


[ Reply to This | # ]
You have to create this UTI.
Authored by: rotaiv on Jun 03, '05 03:44:52PM
I forget to mention, I also followed the steps in the first comment and updated the /System/Library/Spotlight/RichText.mdimporter/Contents/Info.plist and added a new string, com.biapo.vbs-script in the LSItemContentTypes: section.

[ Reply to This | # ]
You have to create this UTI.
Authored by: atverd on Jun 03, '05 03:48:05PM

Are they reported as com.biapo.vbs-script now? If so you have to use the original hint to update Info.plist in RTF mdimporter. If they still reported as dyn.** I don't know. It works for me.



[ Reply to This | # ]
You have to create this UTI.
Authored by: rotaiv on Jun 04, '05 12:04:58AM

They are still showing up as dyn.*. I logged out, moved the application out and back into the Applications folder and same thing.



[ Reply to This | # ]
Re: You have to create this UTI.
Authored by: Uncle Asad on Jun 03, '05 08:57:31PM

You sometimes have to move an app out of /Applications (e.g., to the Desktop) and then back into /Applications, or logout, in order for LaunchServices to pick up any user-generated changes to Info.plist. Perhaps that's the problem with mdimport and UTI types, too.



[ Reply to This | # ]
Re: You have to create this UTI.
Authored by: atverd on Jun 06, '05 01:42:43AM

I think this is it, but the problems is that simple moving a bundle between directories doesn't always update the internal UTIs database (or whatever it is). The only reliable way I could find is to create an archive of the bundle (right click, create archive f.e.), then remove the bundle and empty trash, then unpack the archive back. Looks like LaunchServices cares only about creation and removal of an object and ignoring it's modifications.
I hope someone can point me to a simpler method...



[ Reply to This | # ]
Re: You have to create this UTI.
Authored by: encro on Apr 09, '06 08:59:56AM
You could always take the brute force method of deleting the launch services cache remembering that this will reset a lot of user remembered details with regards to opening/launching applications:

/System/Library/Frameworks/ApplicationServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user


[ Reply to This | # ]
Use Spotlight to index any text file - Globally
Authored by: hardnett on Nov 19, '05 08:49:55AM

I was able to have it work by just using the funny dyn.??? names.



[ Reply to This | # ]
10.4: Use Spotlight to globally index any text file
Authored by: MVasilakis on Jun 21, '09 10:35:29AM

Thank You! x 100



[ Reply to This | # ]