Saturday, July 31, 2010

Script to convert bookmarks from windows IE to Firefox on Apple Mac

If you, like me and other busy bees around :), didn't have time to import bookmarks, etc. before retiring or returning a Windows machine, you'd have just backed-up the raw .html files that IE saves in the favorites folder. Now when you move your backups to Apple Mac, safari browser knows how to work with those .html files and they almost seamlessly integrate into Safari bookmarks and show-up with a .url extension. Then you discover that Safari isn't enough for you (for instance, i couldn't pay my comcast bill using safari) and so you move to Firefox.

You export the bookmarks from Safari into Firefox. Your old IE bookmarks show-up with a .url extension in Firefox (other bookmarks that you added in Safari, i think work fine). So, you click on one of those favorites with a .url extension and Firefox goes nuts with it. On my MBP, firefox was going in an infinite loop when we select a .url bookmark in the favorites - it tries to open infinite windows. Searched quite a bit, but could not find something quick and easy to deal with this issue, so wrote the following to convert bookmarks, so they can be used directly with Firefox. You would get the bookmarks.html file that you will pass as an argument to this script by exporting bookmarks in Firefox. Redirect the script's output to an html file and import it back into Firefox. Enjoy, Vishnu Pendyala

#!/usr/bin/perl

#!/usr/bin/perl

# Script to convert a bookmarks.html file on Mac Book Pro
# with .url file locations imported from Windows IE8 to
# import as Firefox bookmarks.

open FH, "<ARGV[0]";
while (<>) {
 if (/file:/) {
   $filename = $_;
   $filename =~ s#.*file://##g;
   $filename =~ s#\.url".*#.url#g;
   $filename =~ s#%20# #g;
   chomp $filename;
   open FH1, "$filename";
   @urlFile = <FH1>;
   close FH1;
   @line = grep (/^URL=/,@urlFile);
   $url = @line[0];
   $url =~ s#^URL=##g;
   chop $url;
   s#"file:///.*.url" #"$url" #g;
   s#.url</A#</A#g;
 }
 print $_;
}

No comments:

Post a Comment