Skip to content

Instantly share code, notes, and snippets.

@fnando
Created February 24, 2011 23:31
Show Gist options
  • Save fnando/843133 to your computer and use it in GitHub Desktop.
Save fnando/843133 to your computer and use it in GitHub Desktop.
Import Keywurl rules to Google Chrome
require "plist"
require "sqlite3"
APP_SUPPORT = File.expand_path("~/Library/Application Support")
PLIST_FILE = APP_SUPPORT + "/Keywurl/Keywords.plist"
CHROME_FILE = APP_SUPPORT + "/Google/Chrome/Default/Web Data"
plist = Plist.parse_xml(PLIST_FILE)
db = SQLite3::Database.new(CHROME_FILE)
query = <<-QUERY
INSERT INTO keywords VALUES (
NULL, -- id
?, -- name
?, -- keyword
"", -- favicon url
?, -- url
0, -- show in default list
0, -- safe for auto replace
"", -- originating URL
$t, -- date created
0, -- usage count
"", -- input encodings
"", -- suggest url
0, -- prepopulate id
0, -- autogenerate keyword
0, -- logo id
0, -- created by policy
"" -- instant URL
)
QUERY
statement = db.prepare(query)
keywords = plist.first.last
keywords.each do |keyword, options|
url = options["expansion"].gsub(/\{query\}/, "{searchTerms}")
statement.execute(url, keyword, url)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment