Getting Firefox bookmarks into Spotlight


Based on this hint, but nicer and in Perl, this script will convert all of your Firefox bookmarks into .webbookmark files that can be indexed by Spotlight (but I still haven't found a way to open the files with Firefox). Don't run it too often as it's quite intensive - daily should probably be enough.

use strict;
use warnings;
my $meta = "$ENV{HOME}/Library/Caches/Metadata/Firefox";
system("mkdir -p $meta");
system("rm $meta/*.webbookmark");
my $bookmarks = `find \~/Library/Application\\ Support/Firefox/Profiles/ -name 'bookmarks.html'`;
open (IN, $bookmarks);
while (<IN>){
    my $line = $_;
    if (($line =~ m|HREF="(.*?)".*>(.*?)</A>|) && ($1 !~ /^javascript\:/)){
        my $url = $1;
        my $name = $2;
        $url =~ s/&/&amp;/g;
        my $uuid = `uuidgen`;
        $uuid =~ s/\n$//;
        open (OUT, ">$meta/$uuid.webbookmark");    
        print OUT qq|<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">
<plist version="1.0">
        close OUT;    
system("plutil -convert binary1 $meta/*.webbookmark");
system("mdimport $meta");