Copying Search URLs from Safari

I upgraded to Mountain Lion on my laptop. (But not on my desktop development machine yet, just due to healthy pre-shipping-paranoia.)

I wasn’t sure what I’d think of the new combined address/search bar in Safari. I’m skeptical when software tries too hard to divine my intentions. Past experience has shown me that software often gets it wrong, and it becomes very difficult to make it do what I want.

But — at least so far — I’ve been happy with the new address/search bar. It does figure out what I want to do.

I did find an unexpected problem, though: I wanted to give somebody else the URL of a Google search I just did. And I couldn’t.

Screenshot showing Safari’s search/address bar

I asked on Twitter. One way is to drag the magnifying glass into whatever text I’m editing. Another way would be a bookmarklet that gets the current page location. A third way would be an AppleScript script.

I ended up writing a Python script.

Now I can just switch to Terminal (cmd-escape on my machine, thanks to FastScripts), start typing the name of the script, hit Tab, then paste in my search results. (No need even to put them in quotes.) Hit return, and then a search string is on the clipboard.

So it’s not that bad. At least for someone like me who’s only a split-second away from the Terminal at all times. But it’s not nearly as nice as just copying the URL out of the address bar.

It’s weird that the address bar doesn’t always include an address. It feels like a contract has been broken. Maybe it’s one that needed to be broken. (And maybe not.)

Update 11:30 pm: I like Andy Lee’s script and Dominik Porada’s additions.

31 Jul 2012

Archive