# Long URLs and Quicksilver

This is a much simpler version of the script described in this post. Here, the script simply gets the URL of the frontmost Safari tab. No shortening by Metamark, and therefore no alert to let you know when Metamark is done.

 1:  #!/usr/bin/env python
2:
3:  usage = '''
4:  Takes the URL of the frontmost Safari window/tab and
5:  puts it on the clipboard, ready for pasting.
6:  '''
7:
8:  from os import popen
9:
10:  # Get the URl of the frontmost Safari window/tab though AppleScript.
11:  applescript = '''tell application "Safari"
12:    URL of front document
13:  end tell'''
14:
15:  url = popen("osascript -e '" + applescript + "'").read().strip()
16:
17:  # Put the shortened URL on the clipboard.
18:  popen('pbcopy', 'w').write(url)


I call it furl.command and keep it in my home directory where Quicksilver can find it and run it. As with surl.command (the script from the earlier post), I’ve set up a Quicksilver trigger to run furl.command: Control-Option-Command-Shift-U.

With furl and surl, writing about a web pages is much more efficient than before. I can have the page I’m writing about displayed in Safari off to one side of the screen and the writing application--TextMate, usually--on the other side and active. While writing, I can insert the URL (or a shortened form of it) for the page of interest without switching active applications and fiddling around to select and copy the address.