How to import bookmarks into Safari

Try the Safari Debug menu first

If you have Mac OS X 10.3 (Panther) or later, try the following procedure:

  1. Quit Safari
  2. Open Terminal.
  3. Type the following command into Terminal: defaults write com.apple.safari IncludeDebugMenu 1
  4. Open Safari. You should now see a Debug menu (after the Help menu).
  5. In Safari, choose the menu item Debug > Import IE/NS/Mozilla Bookmarks.

Safari will look for bookmarks in the standard places used by each of those other browsers, adding any bookmarks it finds to new collections. Use the Safari menu item Bookmarks > Show All Bookmarks to see the new collections of imported bookmarks; they will have names like "Imported IE Favorites."

You can turn the Debug menu off by typing the following command into Terminal: defaults write com.apple.safari IncludeDebugMenu 0

If this procedure didn't work, try the Perl script in the following section.

Try this if the Debug menu didn't work

This HOWTO assumes that you have Mac OS X with Perl [1], and Safari 1.0 installed, and that you know how to use Terminal and what your home directory is. This is not exactly the kind of thing I'd tell a new user to do, and you can destroy your Safari bookmarks if you're not careful.[2]

This is a mostly manual process, and is intended for advanced users. If you aren't comfortable trying this yourself, find a geek to help.

1. Download importfavorites.pl to your home directory, then quit Safari if it's running.

2. Open Terminal and type the following line. Change {home} to the real path to your home directory), and if your old bookmarks live somewhere besides {Home}/Library/Preferences/Explorer/Favorites.html you need to point to it wherever it lives:

perl importfavorites.pl < {home}/Library/Preferences/Explorer/Favorites.html > oldfavorites.txt

With any luck at all, this will have produced a file called oldfavorites.txt in your home directory that looks sorta like this:

		<dict>
<key>Children</key>
<array>
<dict>
<key>URIDictionary</key>
<dict>
<key></key>
<string>http://livepage.apple.com/</string>
<key>lastVisitedDate</key>
<string>63707346.8</string>
<key>title</key>
<string>Live Home Page</string>
</dict>
<key>URLString</key>
<string>http://livepage.apple.com/</string>
<key>WebBookmarkType</key>
<string>WebBookmarkTypeLeaf</string>
<key>WebBookmarkUUID</key>
<string>0136020A-BB4D-11D7-ADB5-000A95689132</string>
</dict>

			
			
			
			
			
			
			
{more entries}
			
			
			
			
			
			
			
				<dict>
<key>URIDictionary</key>
<dict>
<key></key>
<string>http://www.yamaha.com/</string>
<key>lastVisitedDate</key>
<string>63707346.8</string>
<key>title</key>
<string>Yamaha</string>
</dict>
<key>URLString</key>
<string>http://www.yamaha.com/</string>
<key>WebBookmarkType</key>
<string>WebBookmarkTypeLeaf</string>
<key>WebBookmarkUUID</key>
<string>020A769F-BB4D-11D7-B56D-000A95689132</string>
</dict>
</array>
<key>Title</key>
<string>Imported</string>
<key>WebBookmarkType</key>
<string>WebBookmarkTypeList</string>
<key>WebBookmarkUUID</key>
<string>020B9ECC-BB4D-11D7-8FD7-000A95689132</string>
</dict>

			
			
			
			
			
			
			

If it didn't work, well, you're out of luck. Sorry. Feel free to modify the script to make it work if you know Perl.

For reference, the bold parts of the example above (three per entry) are the only thing that comes from Favorites.html . The italic lines (one per entry and one in the footer) are generated by a system utility called uuidgen ,[3] and these will be different every time you run the script.

If you got a reasonable-looking file, the next step is to paste the converted data into your Safari bookmarks. This is where you can do damage, so please do the backup step.

3. Copy the contents of oldfavorites.txt to the clipboard. You'll be pasting this into your Safari bookmarks file next.

4. Find your Safari bookmarks file. It's {home}/Library/Safari/Bookmarks.plist

5. Make a backup of your Bookmarks.plist (the Duplicate command in the Finder will do fine). Seriously, do it. I killed my bookmarks several times while writing this script and I would have been hosed without a backup.

6. Open Bookmarks.plist in a text editor (TextEdit will do).

7. Find the last occurrence of </array> in Bookmarks.plist . It should be eight or nine lines before the end.

8. Paste the contents of oldfavorites.txt just before the last </array> line in Bookmarks.plist .

9. Save your modified Bookmarks.plist .

10. Open Safari, and you should see your bookmarks in a new group called "Imported". The script does not attempt to preserve the groups in Favorites.html , so you'll probably want to move the ones you like to your preferred locations in Safari and delete the ones you don't need.

Problems?

If you have no bookmarks in Safari after doing the steps above, there are two things you can do: try to fix the problem, or revert to your backup. The backup part should be obvious, just toss the modified file and rename the backup.

Fixing the problem may or may not be possible. The problems I had were with malformed strings in the exported oldfavorites.txt. If you have any non-ASCII characters in the exported names or URLs, you may be able to delete those characters in a text editor and correct the name in Safari. The strings are supposed to be UTF-8 encoded, but the script doesn't bother translating from Mac Roman (the encoding Favorites.html uses), mainly due to extreme laziness on my part. The other problem I had was with unquoted special XML characters & < and > . Those are quoted now, so you shouldn't have problems with them, but there could be something similar that could cause trouble.

The good news is that only a tiny part of the generated oldfavorites.txt contains strings from Favorites.html (the bold parts of the example above), so inspection with a text editor may reveal the problem. The oldfavorites.txt file is mostly duplicated template stuff that should be pretty much immune to errors.

Other problems are beyond the scope of this article.

License

importfavorites.pl version 1, Copyright (C) 2003 Doyle B. Myers. importfavorites.pl comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under the terms of the GNU General Public License.


[1] I'm not sure if Perl comes with the basic system or requires the developer tools.

[2] This script is experimental and has only been tried on one machine, so you may be able to destroy your bookmarks even if you are careful and follow the instructions exactly. Always make a backup before you try something like this.

[3] uuidgen may also require the developer tools, I'm not sure if it's part of the basic system. You can check by just typing uuidgen in Terminal. It should give you a uuid string if it's installed. man uuidgen will explain what it does.

Back to The Amplifier