AppleScript to shorten url of current pages displayed in safari using glo.li

tell application "Safari"

set theURL to do JavaScript "escape(document.URL)" in front document

set tshell to "curl  http://www.glo.li/toolbarshort.php?url=" & theURL & " | textutil -stdin -stdout -convert txt "

set the clipboard to (do shell script tshell)

end tell

Explaination

1. set theURL to do JavaScript "escape(document.URL)" in front document

This line just gets the encoded url

2. set tshell to "curl  http://www.glo.li/toolbarshort.php?url=" & theURL & " | textutil -stdin -stdout -convert txt "

use the shortner, pass the resulting webpage data to textutil to strip out html

3. set the clipboard to (do shell script tshell)

copy result to clipboard

how to

Create a new applescript file
Paste in script and save.
To run on double click save as application.

I use FastScripts which gives you a script menu and allows you to assign keyboard shortcuts. I use ⌃⌥⌘G control-alt-command-G this means I just hit the key combo and the glo.li url is on my clipboard ready for pasting.

Update 2011-03-10

I think something has changes as I now get 'copy'''' after the url, this sorts it out:

tell application "Safari"

set theURL to do JavaScript "escape(document.URL)" in front document

set tshell to "curl  http://www.glo.li/toolbarshort.php?url=" & theURL & " | textutil -stdin -stdout -convert txt "

set theglowurl to (do shell script tshell)

set endchar to (offset of return in theglowurl) - 1

set the clipboard to text 1 thru endchar of theglowurl

end tell