#!/usr/bin/python # # $Id: export_bookmarks 85 2004-09-29 18:07:32Z jay $ # import sys, os, types, codecs import plistlib def read_bookmarks(): bookmarks_file = os.path.join( os.getenv("HOME"), "Library/Safari/Bookmarks.plist" ) return plistlib.Plist.fromFile(bookmarks_file) 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
" % indent for child in node.get("Children", []): filter_bookmarks(child, wanted, found, found*(depth+1)) if found and node_title: print "%s
" % indent elif node_type == "WebBookmarkTypeLeaf": if found: print '%s