WebKit > SearchString from Site

I’m of those who has difficulty to close a tab in Safari, the bad thing about it my computer get slow.

But sometimes it could be very useful to open a webview and search with google to find reference.
And here is my simple example to do that with Takaaki’s WebKit Utilites.

The ASOC Script use set the strings variable but its could be a dialog or anything you like.
The search params are: site: intext:


use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
use webLib : script "WebKit Utilities"

set site to "macscripter.net"
set intext to "use framework"

set intext to my stringWithURLEncoding:intext

-- https://www.google.com/search?client=safari&rls=en&q=site:macscripter.net+intext:%22use framework%22&ie=UTF-8&oe=UTF-8&pws=1
set targetURL to "https://www.google.com/search?client=safari&rls=en&q=site:" & site & "+intext:%22" & intext & "%22&ie=UTF-8&oe=UTF-8&pws=1"
display URL targetURL window size {1000, 900}

-- String to be encoded to URL string.
on stringWithURLEncoding:theURL
	set escapedString to current application's NSString's stringWithString:theURL
	return (escapedString's stringByAddingPercentEncodingWithAllowedCharacters:(current application's NSCharacterSet's URLHostAllowedCharacterSet())) as text
end stringWithURLEncoding: