#!/usr/bin/env python2.3 import sys, os, types, codecs import plistlib from Foundation import * import os import StringIO def read_bookmarks(): plist, format, error = NSPropertyListSerialization.propertyListFromData_mutabilityOption_format_errorDescription_( NSData.dataWithContentsOfMappedFile_(os.path.expanduser('~/Library/Safari/Bookmarks.plist')), NSPropertyListImmutable) data, error = NSPropertyListSerialization.dataFromPropertyList_format_errorDescription_(plist, NSPropertyListXMLFormat_v1_0) return plistlib.Plist.fromFile(StringIO.StringIO(data)) def filter_bookmarks(f, node, wanted, found = 0, depth = 0): node_type = node.get("WebBookmarkType") node_title = node.get("Title") indent = "\t" * depth if node_type == "WebBookmarkTypeList": found = found or (node_title in wanted) if found and node_title: print >> f, "%s
  • %s

    " % (indent, node_title) print >> f, "%s
  • " % indent elif node_type == "WebBookmarkTypeLeaf": if found: print >> f, '%s' % ( indent, node["URLString"], node["URIDictionary"]["title"]) def header(): return """

    Pointless Links

    """ def main(): f = codecs.getwriter("utf-8")(sys.__stdout__) print >> f, header() filter_bookmarks(f, read_bookmarks(), ["BookmarksBar"], found=0) print >> f, footer() if __name__ == "__main__": main()