Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Here's one for LaunchBar users' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Here's one for LaunchBar users
Authored by: macevangelist on Dec 16, '07 01:51:35PM

on run
	set searchDomain to frontmostSafariDomain()
	if searchDomain is false then return false
	
	searchSiteWithGoogle(searchDomain, askForSearchString())
end run

on handle_string(searchString)
	set searchDomain to frontmostSafariDomain()
	if searchDomain is false then return false
	
	searchSiteWithGoogle(searchDomain, searchString)
end handle_string

on searchSiteWithGoogle(searchDomain, searchString)
	set searchString to searchAndReplace(searchString, " ", "+")
	set searchString to searchAndReplace(searchString, "\"", "%22")
	tell application "Safari" to open location "http://www.google.com/search?hl=en&q=site%3A" & searchDomain & "+" & searchString
	tell application "System Events" to if (exists process "LaunchBar") then set visible of process "LaunchBar" to false
end searchSiteWithGoogle

on askForSearchString()
	activate
	return text returned of (display dialog "Please enter a search string:" default answer "")
end askForSearchString



on frontmostSafariDomain()
	-- Init
	set searchDomain to false
	
	-- Checks
	tell application "System Events" to if (exists process "Safari") is false then return false
	tell application "Safari" to if (count of windows) < 1 then return false
	
	-- Get URL of frontmost Safari window
	tell application "Safari" to set currentURL to URL of document 1
	
	
	set prvDlmt to AppleScript's text item delimiters
	
	try
		set AppleScript's text item delimiters to "://"
		set searchDomain to text items 2 thru -1 of currentURL as string
		set AppleScript's text item delimiters to "/"
		set searchDomain to text item 1 of searchDomain as string
		set AppleScript's text item delimiters to "."
		set searchDomain to text items -2 thru -1 of searchDomain as string
	end try
	
	set AppleScript's text item delimiters to prvDlmt
	
	return searchDomain
end frontmostSafariDomain

on searchAndReplace(aString, searchString, replaceString)
	-- No need to continue execution if the string to search for is not in the string
	if aString does not contain searchString then return aString
	
	-- Save delimiters
	set prvDlmt to AppleScript's text item delimiters
	
	try
		set AppleScript's text item delimiters to searchString
		set returnString to text items of aString
		set AppleScript's text item delimiters to replaceString
		set returnString to returnString as string
	on error
		set returnString to aString
	end try
	
	-- Restore delimiters
	set AppleScript's text item delimiters to prvDlmt
	
	return returnString
end searchAndReplace


[ Reply to This | # ]