TinyURL is a cool concept. Many mail clients will either wrap or otherwise distort a URL, depending on the size or characters it may contain. TinyURL creates a URL that you can use to represent a longer one, especially useful for sending to people in mail. The normal process is to submit a URL, at which point you'll be given back a TinyURL to use. Normally you'd take the TinyURL they give and copy and paste into an emai. While it is handy, I decided to figure out a way to do it automatically, using AppleScript, and bypassing the copy and paste procedure.
Read the rest of the hint for the script and notes...
The AppleScript:
-- ####################
-- # -- eMail tinyURL.scpt --
-- # script to automagically get
-- # and paste a tinyURL from
-- # the active Safari window
-- # into Mail.app.
-- # -- by nekvas 2005
-- ####################
-- get the url
tell application "Safari"
set bigURL to the URL of document 1
end tell
-- build the command for curl...quoting the url
set curlCMD to ¬
"curl --stderr /dev/null \"http://tinyurl.com/create.php?url=" & bigURL & "\""
-- grep for tinyurl value
set grepCMD to "| grep 'tinyurl value='"
-- use awk to pull the url out of the retuned page, using " as a delimiter
set awkCMD to "| awk -F'\"' '{ print $2 }'"
-- build the command
set shellCMD to curlCMD & grepCMD & awkCMD
-- run the script and get the result
do shell script shellCMD
set tinyURL to the result
-- pass the value to Mail and put it in the body
tell application "Mail"
activate
set this_message to make new outgoing message with properties ¬
{visible:true, subject:"check out this page", content:("<" & tinyURL & ">")}
end tell
First, a few notes:
Mac OS X Hints
http://hints.macworld.com/article.php?story=200502042003188