A way to search your current website with google ?

Sharing and discussing custom actions for LaunchBar
Post Reply
varmemester
Posts: 13
Joined: Sat Dec 05, 2009 7:02 pm

A way to search your current website with google ?

Post by varmemester » Wed Feb 03, 2010 3:55 pm

Is there a way to search your current website with google, through launchbar. This would be really handy indeed.

Best,
varmemester

dylanpetter
Posts: 7
Joined: Sat Oct 24, 2009 12:07 pm

Re: A way to search your current website with google ?

Post by dylanpetter » Sun Feb 21, 2010 11:46 am

I second this request, in fact, searching your current application in general would be very useful.

Cottser
Rank 1
Rank 1
Posts: 21
Joined: Fri Jan 22, 2010 2:57 am

Re: A way to search your current website with google ?

Post by Cottser » Sat Mar 27, 2010 5:10 pm

If you're using Safari, here's a fun tip.

Get the Google Site Search bookmarklet from here:
http://www.imilly.com/bm.htm

Add it to your bookmark bar. If you have it in the first nine positions, you can access it via keyboard shortcut. For example, put it on the far left of your bookmark bar, then press Cmd-1 to bring it up. Very handy.

I'm not sure if other browsers offer these types of shortcuts.

ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

Re: A way to search your current website with google ?

Post by ptujec » Sat Mar 27, 2010 10:15 pm

this should be close to a solution

Code: Select all

on handle_string(s)
   
   tell application "Safari"
      set theURL to URL of front document
      set theSearchQ to "http://www.google.com/search?q=site:" & theURL & " " & s
      open location theSearchQ
      activate
   end tell
   
end handle_string

norbert
Objective Development
Objective Development
Posts: 648
Joined: Thu Nov 09, 2006 6:30 pm

Re: A way to search your current website with google ?

Post by norbert » Tue Mar 30, 2010 1:26 pm

ptujec, thanks for your script! It would be necessary though, to the extract the hostname from the current document's URL. Otherwise the search would be restricted to the current page instead of the entire site.

A simple approach might extract the substring between the first '//' and the following '/'.

ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

Re: A way to search your current website with google ?

Post by ptujec » Wed Aug 07, 2013 9:46 am

While googling for a solution to this problem I found my own entry ;) I "researched" a bit more and here is the result:

Code: Select all

-- An AppleScript to Google search the current site in Safari - Mac OS X Hints -  http://hints.macworld.com/article.php?story=20071201151055199
-- modified for use with LaunchBar 2013-08-07 by Ptujec

on handle_string(s)
   
   -- set s to text returned of (display dialog "Enter search object" default answer "")
   tell application "Safari"
      set url_current to URL of front document
      set url_current to text ((offset of ":" in url_current) + 3) through length of url_current
      set url_current to text 1 through ((offset of "/" in url_current) - 1) of url_current
      set new_url to "http://www.google.com/search?q=site:" & url_current & " " & s
      make new document
      activate
      set URL of front document to new_url
   end tell
   
end handle_string

on run
   set s to text returned of (display dialog "Enter search object" default answer "")
   tell application "Safari"
      set url_current to URL of front document
      set url_current to text ((offset of ":" in url_current) + 3) through length of url_current
      set url_current to text 1 through ((offset of "/" in url_current) - 1) of url_current
      set new_url to "http://www.google.com/search?q=site:" & url_current & " " & s
      make new document
      activate
      set URL of front document to new_url
   end tell
   
end run

DocterD
Posts: 3
Joined: Sat Jun 21, 2014 11:01 am

Re: A way to search your current website with google ?

Post by DocterD » Sat Jun 21, 2014 11:03 am

Hi,

I wrote an Action for this. It grabs the Default Browser (Safari or Chrome). Gets the Domain and sends it to Google's site search. Have fun.

https://github.com/docterd/launchbar

Post Reply