Feb 08, '05 09:41:00AM • Contributed by: daydream
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!]
