An AppleScript to Google search the current site in Safari

Dec 13, '07 07:30:05AM

Contributed by: ben42

After I updated to Safari 3, AcidSearch stopped working properly, so I uninstalled it. I got Inquisitor instead, but I missed the ability to do a Google site search on whatever site I was visiting. So I put together this AppleScript, mostly assembled from other people's scripts:

set search_object to text returned of (display dialog "Enter search object" default answer "")
tell application "Safari"
    set url_current to URL of front document
end tell
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 & " " & search_object
tell application "Safari"
    set URL of front document to new_url
end tell
[robg adds: To use this, save it as a Script in ~/Library/Scripts/Safari, and make sure the Scripts Menu is enabled. Then just select it while visiting any page in Safari, enter the search term in the box, and you'll run a Google search restricted to that site. It worked fine for me when testing.]

Comments (6)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20071201151055199