If you don't find/write a Chrome extension to do this, you could
A) get a list of your bookmark URLs
I initially thought that the Bookmarks
file in the chrome profile directory was an sqlite3 DB like some of the other files in there. This is incorrect. It looks like a JSON file, so what you'll probably want to do is to import it into some scripting language that has JSON facilities (pretty much anything beginning with 'p' is a safe bet, or even JS if you want to use rhino/spidermonkey/etc) and then extract certain elements.
At first glance, it looks like you'll want the url
property of each object that has a 'type' property equal to "url"
. There are some complications though: for example, this will also include bookmarklets and other things that don't have [relevant] sites, so you'll probably want to run a filter on the results to restrict them to actual web URLs. Whatever you use in B to get the sites might test for this first anyway and return an error on invalid URLs.
B) reduce the list of bookmark URLs (A) to the list of hosts they use
I think this is what you want? Or maybe domains? Except if it's like *.co.uk or similar? This is probably most sensibly done in the same script that you use in A. Another option is to pipe it through a sed | sort | uniq
filter, though with that option you don't end up actually parsing the URL, and you have to bust out some ghetto regex for it. php
is really good at this sort of thing. Well, compared to its appropriateness for most tasks.
C) build a google query URL
...by prefixing each item from B with site:
, joining them with the string +OR+
, and then url-encoding and appending (after a +
) the specific text you want to do a search on. You stick the result on the end of a string like http://www.google.com/search?q=
.
This should give you a URL like http://www.google.com/search?q=site:superuser.com+OR+site:stackoverflow.com+chrome
Then you should be able to just pass that URL as the first argument to a command-line invocation of google-chrome
to get it to open a new tab containing the search results. Note that, least under bash
, you'll need to wrap the URL in quotes so that it doesn't get shell expansion applied to it.
So if you want to, you can roll this into a command line utility, and then just run it by passing your search terms to it. If Chrome is running, you should probably make a copy of the Bookmarks
file before reading it in, and then delete the temp file afterwards.
If you already know JS, and especially if you don't know command-line-friendly scripting languages, it might be easier to learn how how to write a Chrome extension than to rig this up.