AppleScript: search clipboard text on sixhat.net

AppleScript: search clipboard text

When I’m working on something interesting I usually want to check if I’ve already mentioned it the blog. This script allows me to quickly open a new tab on Google Chrome and search on sixhat.net for a text that I’ve copied into the clipboard.

-- This script is based on a script of Computer World
-- http://goo.gl/CZgIw0
 
set url1 to "https://www.google.pt/#q=site:sixhat.net+"
 
tell application "System Events"
	set myquery to the clipboard
end tell
 
-- changes space to plus using function at end of file
set thequery to SaR(myquery, " ", "+")
 
tell application "Google Chrome"
	activate
	set theURL to url1 & thequery
	open location theURL
end tell
 
on SaR(sourceText, findText, replaceText)
	set {atid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, findText}
	set tempText to text items of sourceText
	set AppleScript's text item delimiters to replaceText
	set sourceText to tempText as string
	set AppleScript's text item delimiters to atid
	return sourceText
end SaR

You can easily adapt the script for your own use by changing the variable url1 in the conde. If you prefer to use Safari instead of Google Chrome that is also easy to change in the code above.

To use the script you can use the Script Editor (AppleScript Editor in previous versions of OS X) and then save the script in your User Scripts folder (~/Library/Scripts). If you prefer you can also download the applescript and the edit from there.