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

10.4: Search Firefox bookmarks with Spotlight System 10.4
Tiger only hintFirefox users have been annoyed by the lack of a method for importing Firefox bookmarks into Safari's Spotlight-searchable index. So I wrote a shell script that will do the import; you can schedule it to run as often as you like. Just follow these instructions, and you'll be able to search your Firefox bookmarks via Spotlight.

[robg adds: I tested the script, and it works as described...]
    •    
  • Currently 2.67 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
 
[23,992 views]  

10.4: Search Firefox bookmarks with Spotlight | 20 comments | Create New Account
Click here to return to the '10.4: Search Firefox bookmarks with Spotlight' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Search Firefox bookmarks with Spotlight
Authored by: toadkicker on Aug 30, '05 11:11:47AM

Submit this to bugzilla and get it integrated into Firefox

---
History is written by those who killed heros



[ Reply to This | # ]
10.4: Search Firefox bookmarks with Spotlight
Authored by: stewby on Aug 30, '05 09:08:32PM

As is, it's not even remotely close to being designed to be integrated into Firefox. Someone could make something designed to work from within Firefox and achieve a similar effect, but it wouldn't look like this.



[ Reply to This | # ]
10.4: Search Firefox bookmarks with Spotlight
Authored by: ework on Aug 30, '05 12:29:02PM

This is a great addition to firefox. I think a better solution would be a firefox plugin that could support the Spotlight API, if possible. NeoOfficeJ has an MDI importer that works for OpenOffice.org documents.



[ Reply to This | # ]
slight issue & suggestions
Authored by: stevebr on Aug 30, '05 02:01:17PM

Great idea. I've been looking to do just this.

A few points:

While testing, I noticed that I couldn't see results immediately without manually running mdimport on the new Firefox metadata directory, as:

mdimport ~/Library/Caches/Metadata/Firefox/
Perhaps this might be useful in the script?

Doing so produced several errors, but the number of errors appears to correspond to the number of "bookmarklet" bookmarks I have. I suspect this is being triggered by your pattern matching having an issue with all the (un)escaping that typically goes on in javascript bookmarklets. Not a problem though, since there's no need to index these and the real bookmarks got in just fine. Maybe somebody could confirm this, though?

side note, these had a typo in them:

...mdimport[14351] Expected bookmark file to be a CFDictionary bu it isn't. Aborting.

Also, the 'find' command can be a little more precise. As far as I know, Firefox keeps it's stuff in a known location. Ex:

find ~/Library/Application\ Support/Firefox/Profiles/ -name 'bookmarks.html'
If your home is quite large, you'll notice a bit of chugging while looking for stuff in the authour's version (esp. considering it's suggested to run it every 10 minutes...)



[ Reply to This | # ]
10.4: Search Firefox bookmarks with Spotlight
Authored by: peragrin on Aug 30, '05 02:52:00PM

Um sorry to bea downer but importing bookmarks from firefox to safari is easy since 10.4.

It's either under the file menu or edit menu(i can't remember which) There is an import and then export bookmarks option. When you import bookmarks a new folder is created from the file you specify, along with the date. Then just drag your folders to the bookmark menu.

---
I thought once I was found but it was only a dream



[ Reply to This | # ]
10.4: Search Firefox bookmarks with Spotlight
Authored by: vykor on Aug 30, '05 04:26:14PM

I think you misunderstand. This is about a way to import Firefox bookmarks into Spotlight indexes. Not about juggling bookmarks around browsers.



[ Reply to This | # ]
10.4: Search Firefox bookmarks with Spotlight
Authored by: peragrin on Aug 31, '05 07:03:39AM

it doesn't matter. once you have imported your bookmarks into safari spotlight will index them automatically. It's number 10 on my search results category in spotlight.

---
I thought once I was found but it was only a dream



[ Reply to This | # ]
10.4: Search Firefox bookmarks with Spotlight
Authored by: Han Solo on Aug 31, '05 11:03:35AM
But presumably those Safari bookmarks, once found by Spotlight, will open in... Safari. If Firefox partisans wish to open their Firefox bookmarks in, oh, Firefox, then it does matter to them. And then your suggestion is not nearly as helpful -- or relevant -- as this hint.

That said, if it were possible to change the default browser (from within Safari -- bad Apple!) so that all bookmarks found by Spotlight opened in Firefox -- including Safari bookmarks -- then your point is well taken. I haven't tested this approach... you?

(Personally, I have no issues with Safari, but I know of plenty of folks who will only use Firefox. YMMV.)

[ Reply to This | # ]

10.4: Search Firefox bookmarks with Spotlight
Authored by: genericuser on Sep 01, '05 12:09:40AM

Those bookmarks should open with the default browser regardless of the metadata folder they reside in. I also agree that Apple did a BAD thing by moving the default-browser preference into Safari. There's a system preference called RCDefaultApp (google it) and it lets you set defaults for all the protocols and filetypes. Check it out...



[ Reply to This | # ]
10.4: Search Firefox bookmarks with Spotlight
Authored by: vykor on Aug 31, '05 01:39:58PM

But why go the extra step and use a workaround with two browsers when you can make a direct import? If I were a Firefox user, I'd rather have it "just work" rather than doing the juggling myself.



[ Reply to This | # ]
10.4: Search Firefox bookmarks with Spotlight
Authored by: badger brigade on Aug 30, '05 06:11:24PM

When running this script I get a couple of errors like

sh: line 1: sarge: command not found
sh: line 1: amp: command not found
which makes me a bit worried that the escaping isn't happening properly and sh is running some of the bookmark text as commands when they're preced by backticks (as in the case of 'sarge' above).

Also, is there a way to get Firefox to open .webbookmark files? At the moment, the Spotlight results always open in Safari.

[ Reply to This | # ]

Very dangerous script
Authored by: stewby on Aug 30, '05 09:16:03PM

Yes, the script has no escaping at all. Anything with $ in it will have problems too. The backtick case is by far the most dangerous though, since you could theoretically have a bookmark with text that this script would turn into a destructive command.



[ Reply to This | # ]
Dangerous? Don't think so.
Authored by: jms1 on Aug 31, '05 01:01:40PM

Let's see... the dangerous items, the items which could potentially be controlled by the operator of a malicious web site, are the URL, the page title, and the icon. None of these items are ever exposed to a command line, either directly or by output within a backtick construct- the only things in backticks are the "find" command which locates Firefox's bookmarks.html file, and the word "uuidgen" which is a command to generate UUID numbers which are used as unique filenames.

So the only possible issues would be:

- If an attacker were somehow able to cause files to be created in the user's home directory so that the "find" command returns the wrong file. This threat can be avoided by using a more specific "find" location, as has already been mentioned in one of the replies here.

- If an attacker were able to manipulate the user's system so that the "uuidgen" command ran something other than Apple's /usr/bin/uuidgen.

And if either of these scenarios is possible, you already have bigger problems than this script could expose you to.

Sorry, I don't see anything overly dangerous here.



[ Reply to This | # ]
Dangerous?
Authored by: badger brigade on Aug 31, '05 07:04:28PM
I'm not about to check it, but I think that if a bookmarked site has a title that contains
`rm -rf ~
then you might be in trouble. It's probably not that likely, but it definitely tried to run at least two commands when parsing my bookmarks.

[ Reply to This | # ]
Yes, dangerous.
Authored by: stewby on Aug 31, '05 11:20:18PM

None of these items are ever exposed to a command line, either directly or by output within a backtick construct

You are assuming that none of the bookmarks themselves contain backticks. By the time the

CAT<<...
portion is piped into sh, there are no more shell escapes, so everything in each of those items would be subject to full shell interpretation. Backticks, $, etc.

While the common case would simply be a partially mangled export, this allows arbitrary code execution (obviously vastly more likely to be accidental than malicious, but still a very dangerous thing to run). Deletion of files, upload of files to remote server, you name it. If you don't believe it, try it with a bookmark named `touch ~/uh-oh`



[ Reply to This | # ]
And a fix
Authored by: stewby on Aug 31, '05 11:38:53PM

And as a follow-up, you can make it more correct (no mangled names) and much safer by changing

<<END_BOOKMARK
to
<<'"'"'END_BOOKMARK'"'"'
(Yes, that's single-quote double-quote singe-quote double-quote single-quote on each side)



[ Reply to This | # ]
10.4: Search Firefox bookmarks with Spotlight
Authored by: alys on Aug 31, '05 09:16:44PM

The instructions state:

If you're not familiar with cron, just type this in to schedule it for every 10 minutes:
echo "0,10,20,30,40,50 * * * * /usr/local/bin/ffmd.sh > /dev/null 2>&1" | crontab

If you do that, it will DELETE anything else that has previously been scheduled using cron. At least it does that on my Linux box; I don't have my Mac with me to check - someone with a Mac might want to test to confirm or deny this (backup your crontab file first - if you don't know how to do that, then do NOT test this). The submitter of this hint might want to remove that part of the instructions.



[ Reply to This | # ]
Thanks for the tips, folks.
Authored by: genericuser on Sep 01, '05 11:22:36PM

I made the suggested changes to the script & instructions.


Person who said I should submit to Buzilla -- no thanks, I'd rather just show the Firefox community what a dirty hack I'm resorting to, in hopes that it shows demand for a more ideal solution.

Person who said this would be better implemented as a Firefox plugin -- you're absolutely right. But, a shell script was the quickest path to a working solution for me, so that's what I did. Maybe I'll make a stab at writing a plugin but I'm hoping someone else beats me to it!



[ Reply to This | # ]
now for Camino
Authored by: mici on Oct 11, '05 03:15:18PM

thanks! i tried to recreate the same for my browser of choice, Camino. though it's a mess (and i'm not sed & awk guru, apparently) because i had to format the lines and strip some junk from Camino's XML bookmark file first. other than that, the premise and functionality is same, just copy it from below, it should preserve the lines, et al. please, i encourage you to help smoothening out my trial-and-error-style coding...


#!/bin/sh

rm -rf ~/Library/Caches/Metadata/Camino
mkdir ~/Library/Caches/Metadata/Camino

cat ~/Library/Application\ Support/Camino/bookmarks.xml | sed '{s/<bookmark/\
<bookmark/g;s/<\/folder>//g;s/<folder [^>]*>//g;s/<\/bookmarks>//;}' | grep '<bookmark name="' | awk '{ print "cat <<'"'"'END_BOOKMARK'"'"'>~/Library/Caches/Metadata/Camino/`uuidgen`.webbookmark\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n<key>Name</key><string>" $0 "\nEND_BOOKMARK"}' | sed '{s/<bookmark name="//g;s/" href="/<\/string>\
<key>URL<\/key><string>/g;s/"\/>/<\/string>\
<\/dict><\/plist>/g;}' | sh

plutil -convert binary1 ~/Library/Caches/Metadata/Camino/*.webbookmark


[ Reply to This | # ]
10.4: Search Firefox bookmarks with Spotlight
Authored by: pelton on Feb 14, '10 11:44:58AM
Not that I can get this hint to work any more, but for the curious: the link to the page above is broken, but you can still access it through the Internet Archive:

http://web.archive.org/web/20051231031800/homepage.mac.com/mikemunson/firefox/

[ Reply to This | # ]