Skip to content

Instantly share code, notes, and snippets.

@pjob
Last active December 17, 2015 19:59
Show Gist options
  • Select an option

  • Save pjob/5664544 to your computer and use it in GitHub Desktop.

Select an option

Save pjob/5664544 to your computer and use it in GitHub Desktop.
Download Chrome bookmarks in OSX
#!/usr/bin/env python2.7
# Chrome bookmark mirror on OSX
import json
import os
import urllib2
SAVE_LOCATION = '/tmp/bookmarks'
BOOKMARK_FILE = '/Users/user/Library/Application Support/Google/Chrome/Default/Bookmarks'
bmfile = json.loads(open(BOOKMARK_FILE, 'r').read())
# bmfile.keys() = [u'checksum', u'version', u'roots']
# bmfile['roots'].keys() = [u'synced', u'bookmark_bar', u'other']
# iterate over each root bookmark and grab the children
for root, parent in bmfile['roots'].iteritems():
root_dir = os.path.join(SAVE_LOCATION, root)
# create dir if not exists
if not os.path.exists(root_dir):
os.makedirs(root_dir)
for child in parent['children']:
# Wrap this in try catch in case of javascript bookmarks
# and other key error nonsense
try:
child_loc = os.path.join(root_dir, child['name'])
u = urllib2.urlopen(child['url'])
o = open(child_loc, 'w')
o.write(u.read())
o.close()
except:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment