HINT: Sportlight indexing for Perl, PHP, Ruby, and Fortran Coders 0
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:
- 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. - Go to the Terminal and trigger the re-importation of the directory containing your source code using
mdimport /PathToFiles/ToImport
- 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.

