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

Create an HTML page from Safari's bookmarks UNIX
I was trying to figure out a way to be able to access my my Safari bookmarks from anywhere, without having to dig through the plist folder over ssh (especially on a slow connection). So, I wrote a shell script to do it; it does require plcat, which is part of the free PLtools package.

[robg adds: Set the script to executable (chmod a+x script_name), and edit the script to replace **YOUR USERNAME** with, well, your user name. I tested the script, and it works -- it creates an index.html file in whichever directory you run it in. You can then edit or view the index.html file using any text editor, such as vi.]
    •    
  • Currently 3.00 / 5
  You rated: 2 / 5 (4 votes cast)
 
[16,507 views]  

Create an HTML page from Safari's bookmarks | 11 comments | Create New Account
Click here to return to the 'Create an HTML page from Safari's bookmarks' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create an HTML page from Safari's bookmarks
Authored by: fds on Dec 27, '06 08:05:51AM

Wouldn't it be much simpler to just use the Export Bookmarks… command in Safari's File menu?



[ Reply to This | # ]
Create an HTML page from Safari's bookmarks
Authored by: adrianm on Dec 27, '06 08:10:19AM
I think the point of the hint is doing this from anywhere except from sitting in front of the Mac.

---
~/.sig: not found

[ Reply to This | # ]

Export bookmarks
Authored by: gshenaut on Dec 27, '06 09:07:51AM
I hadn't ever tried that command before, and it does create a .html file containing all the bookmarks, with <h3 folded> titles. If you save it into a web-accessible folder, then you will have global access to your Safari bookmarks from any web browser. If you want, you can easily edit the result to change the title, to remove or add other material, etc.

Greg Shenaut

[ Reply to This | # ]

Create an HTML page from Safari's bookmarks
Authored by: Mikey-San on Dec 27, '06 09:12:01AM

This shell script is not front-page-worthy. Why are we replacing ***YOUR USERNAME*** at all? What's wrong with $HOME (or some equivalent)?

No line breaks. No indentation. No error handling whatsoever. Sigh.



[ Reply to This | # ]
Create an HTML page from Safari's bookmarks
Authored by: cnotarianni on Dec 28, '06 02:38:59AM
edit the script to replace **YOUR USERNAME** with, well, your user name
is not necessary simply modify the first line of the script
plcat ~/Library/Safari/Bookmarks.plist | grep -v key | grep -v dict | grep -v array | grep -v WebBookmark | grep -v Bookmarks | grep -v Address | grep -v Bonjour | grep -v Bookmark | grep -v History | grep -v RSS > base
Sure now the script work with any username!

[ Reply to This | # ]
Create an HTML page from Safari's bookmarks
Authored by: hicksa@gmail.com on Dec 28, '06 05:03:07AM

I know this is a Safari hint, but I occasionally use Firefox and stumbled upon an HTML file of my bookmarks. It is in the users Library, but the best way to find it is spotlight "bookmarks". For example

file:///Users/ahicks/Library/Application%20Support/Firefox/Profiles/iyksksgn.default/bookmarks-1.html



[ Reply to This | # ]
Create an HTML page from Safari's bookmarks
Authored by: peragrin on Dec 28, '06 06:22:31AM

Currently firefox is my main browser but Safari has a couple of useful features.

As the other poster pointed out Firefox stores bookmarks as an HTML file. New bookmarks get's sorted and filed in firefox, then with a simple shell script I FTP them to my website for remote access. The file name is bookmarks.html and I create a link to that file on the main page.

then to update Safari I simply import the bookmarks.

this is fairly quick, but I wish it would could be easier

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



[ Reply to This | # ]
del.icio.us
Authored by: dzurn on Dec 28, '06 09:42:57AM
del.icio.us lets you freely store bookmarks (and tag them) so that you can access them from any computer you can reach.

You can keep all your bookmarks private, or see who else has bookmarked the same pages (and find related bookmarks).

It's free and FireFox has a plugin for it. Yes, it doesn't directly populate the bookmarks menu or toolbar, but I keep my favorites there anyway (which don't change that much).

You can export and import your existing bookmarks at any time. Not sure how well it works with Safari.

---
Madness takes its toll.
Please have exact change.

[ Reply to This | # ]

Create an HTML page from Safari's bookmarks
Authored by: keytohwy on Dec 28, '06 10:05:06AM

How about .Mac? People have blasted this product from Apple, but of the cost of a couple of Starbucks a month, I get exactly what you are after, and a ton of other stuff.

It synchronizes and is available from any web browser, Mac or PC.



[ Reply to This | # ]
Create an HTML page from Safari's bookmarks
Authored by: koncept on Dec 28, '06 05:38:45PM
A while ago, there was some Python code contributed which exported Safari's bookmarks ( or a subset of them ) in "Netscape Bookmark File" format. I have included a revised version of the script which handles binary plists. See the comments in the code for the original URL where usage statements are provided by the original author. By default, this script outputs to stdout.
#!/usr/bin/python
#
# $Id: export_bookmarks 85 2004-09-29 18:07:32Z jay $
# Original script: http://www.macosxhints.com/dlfiles/export_bookmarks.txt
# Original Hint: http://www.macosxhints.com/article.php?story=2004092916004989
#
# Revised (probably poorly) to handle binary plist files via
# parsePlist handler function
#

import sys, os, codecs, plistlib

def read_bookmarks():
    bookmarks_file = os.path.join(
        os.getenv("HOME"),
        "Library/Safari/Bookmarks.plist"
    )
    return parsePlist(bookmarks_file)

def parsePlist(bookmarks_file):
    try:
        return plistlib.Plist.fromFile(bookmarks_file)
    except:
        os.system("/usr/bin/plutil -convert xml1 %s" % bookmarks_file )
        xmlContent = plistlib.Plist.fromFile(bookmarks_file)
        os.system("/usr/bin/plutil -convert binary1 %s" % bookmarks_file )
        return xmlContent

def filter_bookmarks(node, wanted, found = 0, depth = 0):
    node_type  = node.get("WebBookmarkType")
    node_title = node.get("Title")
    if node_title == "BookmarksBar": node_title ="Bookmarks Bar"
    indent = "t" * depth
    if node_type == "WebBookmarkTypeList":
        found = found or (node_title in wanted)
        if found and node_title:
            print "%s<DT><H3 FOLDED>%s</H3>" % (indent, node_title)
            print "%s<DL><p>" % indent
        for child in node.get("Children", []):
            filter_bookmarks(child, wanted, found, found*(depth+1)) 
        if found and node_title:
            print "%s</DL><p>" % indent
    elif node_type == "WebBookmarkTypeLeaf":
        if found:
            print '%s<DT><A HREF="%s" LAST_VISIT="%s">%s</A>' % (
                indent,
                node["URLString"],
                int(float(node["URIDictionary"].get("lastVisitedDate", 0))),
                node["URIDictionary"]["title"]
            )

def header():
    print """<!DOCTYPE NETSCAPE-Bookmark-file-1>
    <HTML>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
    <Title>Bookmarks</Title>
    <H1>Bookmarks</H1>"""

def footer():
    print """</HTML>"""

def main(args):
    sys.stdout = codecs.getwriter("utf-8")(sys.__stdout__)
    header()
    if args: filter_bookmarks(read_bookmarks(), args)
    else: filter_bookmarks(read_bookmarks(), [], found=1)
    footer()

if __name__ == "__main__": main(sys.argv[1:])   


[ Reply to This | # ]
Create an HTML page from Safari's bookmarks
Authored by: qadkjyjaagbz on Jan 02, '07 08:54:57AM
Here is another script to do the same thing, that doesn't require you to install any additional software (on 10.4 at least):

#!/bin/bash
bookmarks=$HOME/Library/Safari/Bookmarks.plist
plutil -convert xml1 $bookmarks
sed >/tmp/plist2html.xsl <<EOF
<xsl:stylesheet version='1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
xmlns='http://www.w3.org/1999/xhtml'>

<xsl:output method='xml' indent='no'
doctype-public='-//W3C//DTD XHTML 1.0 Transitional//EN'
doctype-system='http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'
omit-xml-declaration='no'
media-type='application/xhtml+xml; charset=utf-8'/>

<xsl:template match='/'>
<html>
<head>
<title>Safari Bookmarks</title>
</head>
<body>
<h1>Safari Bookmarks</h1>
<ul>
<xsl:apply-templates select='plist/dict'/>
</ul>
</body>
</html>
</xsl:template>

<xsl:template metch='array'>
<ul>
<xsl:apply-templates/>
</ul>
</xsl:template>

<xsl:template match='dict'>
<li>
<xsl:choose>
<xsl:when test='string[text()="WebBookmarkTypeLeaf"]'>
<xsl:apply-templates select='key[text()="URIDictionary"]/following-sibling::dict[1]' mode='URIDictionary'/>
</xsl:when>
<xsl:when test='string[text()="WebBookmarkTypeList"]'>
<xsl:if test='key[text()="Title"]'>
<h3><xsl:apply-templates select='key[text()="Title"]/following-sibling::string[1]'/></h3>
</xsl:if>
</xsl:when>
</xsl:choose>
<xsl:apply-templates select='key[text()="Children"]/following-sibling::array[1]'/>
</li>
</xsl:template>

<xsl:template match='dict' mode='URIDictionary'>
<a href='{string[1]}'>
<xsl:value-of select='key[text()="title"]/following-sibling::string[1]'/>
</a>
</xsl:template>

</xsl:stylesheet>
EOF
xsltproc /tmp/plist2html.xsl $bookmarks >index.html


[ Reply to This | # ]