AppleScript to get Google search URL

Aug 02, '12 07:30:00AM

Contributed by: kirkmc

In Safari 6, with the new combined URL and search field, if you type search terms into the field, then press return, you'll get a Google page with the results, but you won't get a search URL in the address field. Some people want to save searches at times. Macworld's Dan Frakes tweeted an AppleScript which does just that and Many Tricks developer Peter Maurer improved on it. Run the script and it will get the URL for the frontmost tab then send it to the clipboard, from which you can paste it where you want.

tell application "Safari"
	set the clipboard to URL of current tab of window 1 as string
end tell
As Dan Frakes later pointed out on Twitter, you can also drag the favicon to a finder window. You can double-click the resulting file to redo the search, or you can press the Spacebar to Quick Look it and see a live search with clickable links. For a search, the favicon is the magnifying glass icon at the left of the search field.

So, how many other ways can you find to save a Google search URL?

Update: Jordan Kay posted an even shorter version on Twitter:
 tell application "Safari" to set the clipboard to URL of current tab of window 1 as string

Comments (2)


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