Loading ...
Sorry, an error occurred while loading the content.

OT: Applescript to search current web site via Google

Expand Messages
  • John Rethorst
    I visit a lot of web sites with search functions, some of which work, but not as well as Google s search. Google can be directed to search a single site, on
    Message 1 of 2 , Nov 10, 2006
    • 0 Attachment
      I visit a lot of web sites with search functions, some of which work, but
      not as well as Google's search. Google can be directed to search a
      single site, on their advanced page, but you can save a step by running
      this script (from the Apple script menu or, better, from the free
      FastScripts Lite), with the site you want to search already in your browser.
      Change the browser name in the second line if you want (your default
      browser should be changed in program settings to match):



      property searchText : ""

      tell application "Safari" to set rawURL to URL of document 1

      set url1 to text 8 thru length of rawURL

      if url1 contains "/" then
      set offset1 to offset of "/" in url1
      set thisURL to text 1 thru (offset1 - 1) of url1
      else
      set thisURL to rawURL
      end if

      set searchText to text returned of (display dialog "Search "" & ¬
      thisURL & "" via Google for:" default answer searchText)

      open location "http://www.google.com/search?&rls=en&q=" & ¬
      searchText & "+site:" & thisURL
    • John Rethorst
      Posting changed some smart quotes to dumb quotes. Try: property searchText : tell application Safari to set rawURL to URL of document 1 set url1 to text 8
      Message 2 of 2 , Nov 11, 2006
      • 0 Attachment
        Posting changed some smart quotes to dumb quotes. Try:


        property searchText : ""

        tell application "Safari" to set rawURL to URL of document 1

        set url1 to text 8 thru length of rawURL

        if url1 contains "/" then
        set offset1 to offset of "/" in url1
        set thisURL to text 1 thru (offset1 - 1) of url1
        else
        set thisURL to rawURL
        end if

        set searchText to text returned of (display dialog "Search " & ¬
        thisURL & " via Google for:" default answer searchText)

        open location "http://www.google.com/search?&rls=en&q=" & ¬
        searchText & "+site:" & thisURL

        John R.
      Your message has been successfully submitted and would be delivered to recipients shortly.