Automating export of Firefox 3 bookmarks and history from command-line/cron
Firefox 2 used a bookmarks.html file for bookmarks. History was in a mork file that was incomprehensible. Firefox 3 uses SQLite for both these. Export manually is simple from the Bookmarks-Organize Bookmarks menu option. This page gives us info on how to automate bookmarks export using about:config, however this export happens:
- only for bookmarks, not history
- only when Firefox is shutdown
So the only option I had was to access the database via python or ruby. Both have packages for that, the python one comes with python (no install) so i tried that and got “database locked”. Googled but no one had an answer for that.
Finally, I just copied the file (hint courtesy), places.sqlite to places1.sqlite and was able to open (pls note that FF3 is still running).
It seems I already have a program called “sqlite3” on my os x. Loading it on the backup file showed me that I had various output formats such as html, csv, list etc. I could output to a file … same stuff as any other sql client – if you’ve used mysql, you’d be very familiar.
Now automating the output of the history and bookmarks without shutting firefox, and without user intervention in any format is as simple as:
cd /Users/john/Library/Application\ Support/Firefox/Profiles/8j7l8qg8.default
cp places.sqlite places1.sqlite
sqlite3 'places1.sqlite' <<!
.dump html
.output moz_places.html
select url,title from moz_places;
!
This may be run as a cronjob. Be sure to change the path in the cd command to your user, and edit the dump to list or csv as required. The output would go into some work folder for other applications to access easily. The existing location has a space which can cause bash programs to gripe (wish they would make life easier for us command-line junkies).
Bookmarks are stored in the moz_bookmarks file with title but not url. To get the url you would link to moz_places with the fk field as:
select a.url, b.title from moz_places a, moz_bookmarks b where a.id=b.fk and b.title like '%zsh%';
in order to dump all rows, just give:
select a.url, b.title from moz_places a, moz_bookmarks b where a.id=b.fk;
Before processing this text you may wish to filter out pages your other apps do not need such as google searches, your own websites/blogs, pagead urls etc. Also you may want to remove duplicates with the “sort -u” command.
Hope this helps.
—
# join pairs of lines side-by-side (like ‘paste’)
$ cat | ruby -pe ‘$_ = $_.chomp + ” ” + gets if $. % 2′
December 1, 2008 at 8:58 pm
Thank you for the information. However I couldn’t get this solution to import back into Firefox (the entire point) and wound up going with the about:config trick after spending quite a bit of time trying to get this to work well.