Skip to content

Instantly share code, notes, and snippets.



Last active Jan 15, 2021
What would you like to do?
Import search engine definitions by CLI

Import Search Engines to Chrome

If your daily life means bouncing between github, JIRA, jenkins, AWS, etc... (and your team), you want to standardize shortcuts

This script will update your preferences, and make for glorious browser efficiency.


⚠️ shut down Chrome first, otherwise it shall fail due to locking.

cat sample.json | python
### Import Search Engines to Chrome
### Python 2; OSX
import os
import sqlite3
import json
import sys
def load(db, *records):
conn = sqlite3.connect(db)
c = conn.cursor()
max_id = int(c.execute('select max(id) from keywords').fetchone()[0])
for record in records:
if c.execute('select 1 from keywords where keyword = ?', [record['keyword']]).fetchone():
print "Record already exists: %s" % (record['short_name'])
max_id += 1
record['id'] = max_id
keys = list(record.keys())
values = map(lambda k: record[k], keys)
c.execute("INSERT INTO keywords (%s) VALUES (%s)" % (",".join(keys), ",".join(["?"] * len(keys))), values)
print "Record added: %s" % (record['short_name'])
if __name__ == '__main__':
db = os.path.expanduser("~/Library/Application Support/Google/Chrome/Default/Web Data")
data = json.load(sys.stdin)
if isinstance(data, dict):
data = [data]
load(db, data)
"short_name": "Github",
"keyword": "g",
"favicon_url": "",
"url": "{searchTerms}",
"safe_for_autoreplace": 0,
"date_created": "13162568566000000",
"usage_count": 100,
"last_modified": 13162568566000000,
"last_visited": 13188056277435693
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment