Automatically copy selected text and paste it on Safari's location bar

Hi, I’m a recent switcher also trying to switch from Firefox to Safari, and I found I could do without most extensions, except for one: AutoContext.

I gave it some thought and figured I could recreate most of its functionality that is important to me if I could get the selected text to automatically populate the URL of the current tab, or at the very least be automatically copied to the clipboard. So I did a little reading on Applescripts and tried both scripts:


on select theText
	tell application "Safari" to set clipboard to theText
end select


on select theText
	tell application "Safari" to set URL of document to theText
end select

I run them both nothing happens. What am I missing? What should I do? Is it even possible?

Hi,

try this


tell application "Safari"
	activate
	tell document 1
		set URL to (do JavaScript "\"\"+window.getSelection();")
	end tell
end tell

You have to put the clipboard, not just clipboard .

Thanks everyone. I cracked it with the help of you guys and these articles. Here’s what my script looks like:


using terms from application "Quicksilver"
	on process text theQuery
		tell application "Safari"
			activate
			set selecTxt to (do JavaScript "(getSelection())" in document 1)
		end tell
		
		set yubnub to "open [url=http://www.yubnub.org/parser/parse?command=]http://www.yubnub.org/parser/parse?command="[/url]
		set theCommand to yubnub & quoted form of (theQuery & " " & selecTxt)
		do shell script theCommand
	end process text
end using terms from

I saved it as “context” and added it as a trigger and now I can select text on a page, press Ctrl+Cmd+C and just enter ‘wp’, ‘g’ etc + ‘enter’ to search the selected text on wikipedia, google etc, through one of the countless aliases in YubNub.

Thanks!

PS: Am I crazy or did someone else comment with a script that saved stuff to a file in the desktop? I used stuff from that as well and would like to thank whomever it was.