Urania

A blog named for the muse of Astronomy containing musings by an astronomer

HINT: Sportlight indexing for Perl, PHP, Ruby, and Fortran Coders

Posted on July 12, 2007 by Juan

This hint is my writeup based on a similar hint at MacOS X Hints for Making Spotlight index PHP files.

I 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 SourceCode.mdimporter is needed. First find the type (according to
Spotlight) of the files you want indexed, as PerlFile.pl using this command (via the Terminal):

mdimport -n -d1 PerlFile.pl

which outputs something like:
Import 'PerlFile.pl' type 'public.perl-script' no mdimporter

Now take that file type (public.perl-script) and add it to the Info.plist file located at /Library/Spotlight/SourceCode.mdimporter/Contents/Info.plist (If you can’t find this file, you likely installed Apple’s MacOS X Developer Tools yet). Add it in the array for LSItemContentTypes.

I added:

<string>public.perl-scrip</string>t<string>
public.php-script</string><string>
public.python-script</string><string>
public.ruby-script</string><string>
public.fortran-source</string>

Now you can index your source code files in one of three ways:

  1. Go to a Terminal prompt and type:
    mdimport -r /Library/Spotlight/SourceCode.mdimporter

    to process all your source code files and import them into Spotlight’s database.
  2. Go to the Terminal and trigger the re-importation of the directory containing your source code using
    mdimport /PathToFiles/ToImport
  3. Go crazy and re-import everything on your drive using
    sudo mdimport /

To see what is going on, add the -d1 switch to the mdimport command.

Leave a Reply




↑ Top