◀   |   |   ▶
◀   |   |   ▶

Google サイト内検索を簡単にするためのスクリプト



Google のサイト内検索を簡単に実行するための AppleScript です。

Bookmarklet を使って同様のことを行うものもあるようですが、ドメイン単位でのサイト内検索しかできなかったりと、私にとってはあまり使い勝手がよくないものしか見つからなかったので、作ってみました。

このスクリプトでは、例えば iBlog サイトの場合、カテゴリ内検索にも使えます。Safari 専用です。


ダウンロード:Google_Site_Search.bz2

<使い方>

  1. 解凍してできあがった Google_Site_Search.scpt をホームフォルダ内のライブラリ/Scripts またはその中のサブフォルダ内に入れます。
  2. Safari でサイト内検索をしたいページを開いた状態で、スクリプトメニューから実行します。たとえばブログの場合、エントリページからスタートしても OK です。
  3. サイト内検索の対象にする URI がダイアログで示されますので、必要に応じて編集してください。
  4. 2番目のダイアログに検索語を入れます。複数の検索ワードを使う場合は、スペース区切りです。ただ、複数の検索語をクオーテイションマークでくくっておこなう「フレーズ検索」には対応していません。複数語の「and 検索」になってしまいます。

3. で示される URI は、たとえばこのブログ内のエントリページの場合、
homepage.mac.com/kaoru_ari/iblog/C1308878031/E495390368
です。このまま実行すれば、エントリページ内での検索になります。意味がありませんね…
これを編集して
homepage.mac.com/kaoru_ari/iblog/C1308878031
とすればカテゴリ内検索に。
homepage.mac.com/kaoru_ari/iblog
とすればブログ内検索に。
homepage.mac.com/kaoru_ari
とすれば私のドメイン内での検索に。
homepage.mac.com
とすれば、homepage.mac.com 全体での検索になるというわけです。

スクリプトの中身はこうです。興味のある方は、読んでみてください。

tell application "Safari"
  set the_url to the URL of document 1 as text
  my replaceText(the_url, "http://", "")
  set the_url to the result
  set the_num to number of items of the_url
  repeat with i from 1 to the_num
    if item -i of the_url is "/" then
      set the the_minus_num to i
      exit repeat
    end if
  end repeat
  set search_site to ""
  repeat with i from 1 to (the_num - the_minus_num)
    set search_site to search_site & item i of the_url
  end repeat
  display dialog "Edit URI" default answer search_site buttons {"Cancel", "OK"} default button 2
  copy the result as list to {text_returned, button_pressed}
  my replaceText(text_returned, "/", "%2F")
  set search_site to the result
  --
  display dialog "Enter search word(s)" default answer "" buttons {"Cancel", "OK"} default button 2
  copy the result as list to {text_returned, button_pressed}
  set word_num to the number of words of text_returned
  repeat with i from 1 to word_num
    if i is 1 then
      set search_word to word 1 of text_returned
    else
      set search_word to search_word & "%20" & word i of text_returned
    end if
  end repeat
  --
  open location ("http://www.google.com/search?q=" & search_word & "+site%3A" & search_site)
end tell
on replaceText(targetStr, pre, pro)
  set CurDelim to AppleScript's text item delimiters
  set AppleScript's text item delimiters to pre
  set targetStr to text items of targetStr
  set AppleScript's text item delimiters to pro
  set targetStr to targetStr as string
  set AppleScript's text item delimiters to CurDelim
  return targetStr
end replaceText

投稿: 2005年06月19日 (日) at 07:46   | | | |

◀   |   |   ▶
◀   |   |   ▶