Nat TaylorBlog, Product Management & Tinkering

Chrome Bookmarks in MacOS Spotlight Search

Published on . Updated on

Spotlight is incredibly convenient but it only supports Safari bookmarks. I came up with the following solution to add Chrome bookmarks. I run this script periodically, and it writes out .webloc files that get picked up by Spotlight.

#!/usr/bin/env python3

"""Write Chrome Bookmarks as .webloc files in a folder so they show up in Spotlight"""

import json
import logging

template = """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>URL</key>
	<string>{url}</string>
</dict>
</plist>"""

with open('/Users/ntaylor/Library/Application Support/Google/Chrome/Default/Bookmarks') as f:
    bookmarks = json.load(f)

keepers = [c for b in bookmarks['roots']['other']['children']
             if 'children' in b and b['name'] == 'Jesica' for c in b['children']]

for k in keepers:
    logging.info(k['name'])
    print(k['name'])
    with open(f'/Users/ntaylor/Links/{k["name"]}.webloc', 'w') as f:
        f.write(template.format(url = k["url"]))

Popular Posts

Post Navigation

«
»