I've only recently discovered the usefulness of Apple's Spotlight search tool. For some reason I'd never really clicked that it could be a very handy little launcher for applications and documents, until I noticed the Mac techo guy who came to plug all the wires in and adjust the tappets on my new 12 core machine at work <smirks>. But now I'm addicted - I've even mapped the Spotlight keyboard shortcut on to one of my mouse buttons and got rid of Butler.
So of course I couldn't be satisfied with just launching apps and dox, I want all my webs to appear in Spotlight too. After some googling I find that this isn't as easy as it would appear, especially if you don't want to use Safari.
Well here's what I came up with. A modification of this modification of a Perl Script that produces URL files. Why URLs? Well they're simple than webbokmarks, and since FireFox doesn't read the content of .webbookmark or .webloc filesbut relies on data in the resource fork, weblocs and webbokmarks didn't work anyway. Bad Firefox.
So I need a little helper app to read the url file and open FF at the right page. It's simple enought to do with a shell script or a bit of perl etc, but the OS won't let you assign these as the default app for the file type. So I used an AppleScript as a wrapper.
So if you want your Bookmarks to appear in Spotlight here's what you have to do.
first run this perl script:
#!/usr/bin/perl
use strict;
use warnings;
my $meta = "$ENV{HOME}/Library/Caches/Metadata/Firefox";
system("mkdir -p $meta");
system("rm $meta/*.url");
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;
$url =~ s/&/&/g;
my $name = $2;
$name =~ s{[/:;\*\\\"\'\.\|]+}{-}g;
# my $uuid = `uuidgen`;
# $uuid =~ s/\n$//;
print $line;
open (OUT, ">$meta/$name.url");
print OUT "[InternetShortcut]\nURL=$url\n";
close OUT;
}
}
You can copy and paste it or download it here. To run, just open a terminal cd tot he directory you downloaded the script (usually cd ~/Downloads will get you there) and type perl ffbm.pl
If you want to open the links with Firefox or Chrome, read on:
FF on the mac doesn't handle .url files or .webloc or .webbokmark files properly. We need a little helper to read the files and kick the contents to Firefox / Chrome.
So I've created this applescript. Plonk it in your Applications folder (or wherever). This basically munges the .URL file to get the URL out of it, and uses your default web browser to open it. Here's the code:
on open theURLfile --called when the OS sends a URL file to the script
openURLfile(theURLfile)
end open
openURLfile(choose file) --called when the user just runs this script by double clickingon openURLfile(theURLfile) --the actual Hoo-Hah set URLfilePpath to POSIX path of theURLfile set theURL to (do shell script "cat \"" & URLfilePpath & "\"|grep \"URL=\"|sed \"s/.*=//\"") do shell script "open " & theURL --the OSX open command opens whatever you give it according to your default application choiceend openURLfile
Now there's one last step. You have to associate the .url files with this wwwopener application. After running the perl script go to <home>/Library/Caches/Metadata/Firefox and choose one of the .url files that should be there. Hit Cmd-i to get information and change the Open With from Safari (or whatever it defaults to) to wwwopener.app (this doesn't change your default web browser, it just makes URL files open with the helper app, which then opens them in the default browser. If you're an Opera or Safari user you don't need to worry, as they read .URL files fine.
Comments [0]