Search Active Webpage?

General discussions about LaunchBar
Post Reply
Posts: 7
Joined: Sat Oct 24, 2009 12:07 pm

Search Active Webpage?

Post by dylanpetter » Tue Aug 20, 2013 5:55 am

Basically, rather then pressing ⌘F when I want to search a webpage (or document for that matter), I would like to use LaunchBar to initiate the search. Does anyone know if this is possible? Thanks!

Rank 1
Rank 1
Posts: 23
Joined: Sun Nov 09, 2008 3:25 am

Re: Search Active Webpage?

Post by Kicweed » Tue Aug 20, 2013 4:11 pm

I guess the easiest way would be to write a small Applescript that would initiate your browser's search functionality. You'd call that action from LB, pass your search string and all it would do would be to call your browser's or your document's app search function and paste the parameter.

I'm not fluent in Applescript so I can't write it for you, but I guess it would go something like:

Code: Select all

on handle_string(searchString)
    tell FrontMost Application
        start the search function --usually Cmd + F
        paste searchString
        press Enter
    end tell
end handle_string

Here's Launchbar's documentation page on how to pass parameters to called Applescripts.

I'm rooting for the simple Applescript approach because searching from within Launchbar is more complicated than it sounds. For example, in the case of a web browser:

  1. You need to fetch the HTML source of the current page (not super easy since web pages might be combinations of other pages, IFRAMEs etc)
  2. Parse the HTML to get the actual text content and not the HTML code (not super easy since dynamic pages full of JavaScript make it non-straightforward)
  3. Search the text (the only thing that sounds easy to me, already doable for text files)
  4. For each result found in Launchbar, command the browser to scroll to that point (not super easy because we've dropped the page's structure when we dropped the HTML code at step 2)

Post Reply