This macro (available here) leverages KM to chain together the functionality of some disparate productivity tools, including Automator, LaunchBar and Brett Terpstra's SearchLink tool, both of which must be installed to make this work. There is probably an elegant coding solution to this but ... I am not a coder! Anyway, it's fun tinkering!
(Side note: I'm not going to go into all of the functionality of SearchLink. I will let you all explore SearchLink on Brett Terpstra's site and follow the instructions for installation and use. Suffice it to say that it is an outstanding tool for exploiting Markdown syntax to its fullest. It was designed to facilitate quick inputting of links into documents prepared for web publishing.)
OK, so we sometimes like to do a quick web search while reading an article, say, in order to get up to speed quickly on an item with which we are unfamiliar appearing in the text of the article. Or maybe we're writing something in a text editor and we want to do a quick search on an item to which we've referred in the text. Instead of activating your browser in order to execute the search and view results, this macro takes a text selection as a search query, runs a search and returns the top hit to a pop-up browser window which does not require Safari activation and can be dismissed immediately with the Escape key.
First, the macro copies the text selection, let's say it's "Ed Gillespie" (cough ... loser ... cough). It then wraps the clipboard text in SearchLink syntax. The syntax will cause SearchLink to run a top hit search and return the top hit URL to the clipboard (as opposed to outputting a Markdown link, for example). The syntax looks like this:
!g Ed Gillespie !!^
The macro then executes a workflow...
... which sends the selected text, now copied and wrapped, to LaunchBar, as a text item.
The macro now hits the TAB key to point the text item in Launchbar to an action. Another workflow is called which points LaunchBar to the SearchLink action (SearchLink must be accessible via Launchbar). (The SearchLink action is a service workflow that SearchLink installs in your Services directory).
LaunchBar will look like this for a second:
The macro then executes the SearchLink action by hitting Return. SearchLink returns a top hit URL to the clipboard.
The macro then activates an Automator application I made called "Preview URL App" (available here and see my KM Macro Library post here). This app pops up a browser window, without opening Safari, using any URL in the clipboard. It will now be used to pop up a browser window for the top hit URL returned by SearchLink.
Finally, the macro clicks the center of the screen, and thus presumably the center of the pop up window, in order to bring it to the front (for some reason, the pop up is never at the front when it materializes). This allows you to dismiss the window with the Escape key or either the Cancel or OK button on the bottom of the window.
Here it is in action:
Of course, if you don't like the top result, you can always go ahead and do an ordinary search using the full powers of your browser. This macro is built for speed (I like to think), not necessarily accuracy!
You can also fool around with it and set it up to accept a search query, which you could then narrow by adding, for example,
site:wikipedia.org Ed Gillespie, which SearchLink would turn into
!g site:wikipedia.org Ed Gillespie !!^
and you would almost certainly get the Wikipedia page as the top hit.