Automatically send a TinyURL from Safari via Mail.app
Tue, Feb 8 2005 at 9:41AM PST • Contributed by: daydream
Tue, Feb 8 2005 at 9:41AM PST • Contributed by: daydream
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:
Directions:
[robg adds: This worked for me. If you like the TinyURL service, you might want to check out the TinyRoulette hint from a while back. Quite fun when you have some time to waste -- though you're not sure where you might wind up, so it's not really work safe!]
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:
- You may need the BSD subsystem installed for this to work, as it does use curl, grep, and awk to do it's thing
- You have to have the ScriptMenu from Apple installed.
- There isn't much error checking in this script, but it should work just fine. Even crazy characters embedded in URLs should be fine.
- You should be able to see how to modify various parameters, but be careful.
Directions:
- Copy the script text from this hint.
- Paste it into a new script in Script Editor.
- Save it into ~/Library/Scripts/Applications/Safari as a Script, and name it whatever you like. You may or may not have to create some or all of these folders.
[robg adds: This worked for me. If you like the TinyURL service, you might want to check out the TinyRoulette hint from a while back. Quite fun when you have some time to waste -- though you're not sure where you might wind up, so it's not really work safe!]
•
[16,167 views]
