Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,000 hints and counting!

Automatically send a TinyURL from Safari via Mail.app Internet
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:
  • 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.
I'm sure this could be done a better way, but being that I'm not an AppleScript god, I decided to get this done with the toolbox approach, using curl, grep and awk.
Directions:
  1. Copy the script text from this hint.
  2. Paste it into a new script in Script Editor.
  3. 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.
From there, you should be able to access it using the AppleScript menu in Safari. Selecting the script will get a TinyURL for the foremost browser window, create a new mail with Mail.app, and paste the TinyURL into the body. Hope this works for everyone.

[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!]
    •    
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[16,167 views]  

Automatically send a TinyURL from Safari via Mail.app | 21 comments | Create New Account
Click here to return to the 'Automatically send a TinyURL from Safari via Mail.app' hint
The following comments are owned by whomever posted them. This site is not responsible for what they say.
Automatically send a TinyURL from Safari via Mail.app
Authored by: stift on Tue, Feb 8 2005 at 10:49AM PST
;-) for the link

[ Reply to This | # ]
Automatically send a TinyURL from Safari via Mail.app
Authored by: daybrother on Tue, Feb 8 2005 at 11:04AM PST
Am I the only one that has bad experiences with tiny URL? 9 times out of 10, when I click on a tiny link anywhere I get nothing but a 404-like page that says the link is no longer valid.

[ Reply to This | # ]
Alternative service
Authored by: jokke on Tue, Feb 8 2005 at 11:40AM PST
Try MetaMark instead. They even have a Service menu item :)

---
http://jokke.dk | Pulling the trigger at port 80

[ Reply to This | # ]

Automatically send a TinyURL from Safari via Mail.app
Authored by: Tarlach on Tue, Feb 8 2005 at 12:15PM PST
to send a URL via mail, I use this bookmarklet.

javascript:t=document.title;x=(window.location);window.location='mailto:?Subject='+t+'&Body='+t+'%20%20'+x+'%20';

Create a new bookmark and copy that into the address then save it as send URL or whatever youw ant to name it.
then when you want to send the URL click on it and mail will open with the url and the title of the page in your email.
I use it all the time.
Works great!

[ Reply to This | # ]
Automatically send a TinyURL from Safari via Mail.app
Authored by: snit on Tue, Feb 8 2005 at 12:19PM PST
I use TinyUrl... and just have this bookmarked:

http://snipurl.com/teindex.php

Works great

[ Reply to This | # ]
Automatically send a TinyURL from Safari via Mail.app
Authored by: bakalite on Tue, Feb 8 2005 at 12:34PM PST
I tried to modify the script to just past the tiny url to the clipboard, but it doesn't work. I looked at a few examples of using the clipboard online, and can't figure out why it doesn't work. I guess this is the reason I don't code...


[code]
-- ####################
-- # -- 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

--put the result on the clipboard
set clipboard to tinyURL as text
[/code]

[ Reply to This | # ]
Automatically send a TinyURL from Safari via Mail.app
Authored by: luhmann on Tue, Feb 8 2005 at 5:50PM PST
Anyone know how to make this work with OmniWeb? I tried changing "safari" to "omniweb" but no luck.

[ Reply to This | # ]
TinyURL for OmniWeb
Authored by: Krioni on Fri, Feb 11 2005 at 11:09AM PST
Just change the Safari section to:

tell application "OmniWeb"
	set bigURL to address of browser 1
end tell
I didn't see if any other improvements could be made to the script, but that would let it work with OmniWeb. I'd just use the bookmarklet another poster in this thread described. There are a lot of fun things you can do with TinyURL.

[ Reply to This | # ]
TinyURL for OmniWeb
Authored by: Krioni on Fri, Feb 11 2005 at 11:18AM PST
Oops, I posted much too late - obviously others already posted this.

[ Reply to This | # ]
keyword
Authored by: spatfield on Tue, Feb 8 2005 at 7:12PM PST
If you use a keywords feature (like AcidSearch) on your browser, here is the base URL for that:

http://www.macosxhints.com/article.php?story=200502042003188

[ Reply to This | # ]
babyurl.com
Authored by: lazyjunk on Tue, Feb 8 2005 at 7:53PM PST
You can use babyurl.com

which provides the same service, but the pop-up window has a button that will automatically send it to mail.app [or whatever your default mail app is].

Also, there's a java script link on their site that you can use, and put in your safari bookmark bar, so you can EASILY click on the link in your bookmark bar, and i t'll create everything for you.



[ Reply to This | # ]
Automatically send a TinyURL from Safari via Mail.app
Authored by: neknek on Wed, Feb 9 2005 at 10:26AM PST
It's great, and works well, but Speakeasy blocks it as it's being sent. Their bulk mail filter must be set to deny TinyURLs... I'm going to email them and ask.

[ Reply to This | # ]
Bookmarklet
Authored by: on Wed, Feb 9 2005 at 5:15PM PST
I loved this hint and combined several other comments into a nice bookmarklet; I ended up using babyurl.com because they have a nice clean interface and an email shortened url link:

javascript:void(window.open('http://babyurl.com/index.php?bu_op=createurl&bu_url='+location,'TinyURL','location=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=425,height=200'))


[ Reply to This | # ]
Automatically send a TinyURL from Safari via Mail.app
Authored by: daydream on Wed, Feb 9 2005 at 11:53PM PST
To get this working with OmniWeb, simply change the second line from:
set bigURL to the URL of document 1
to:
set bigURL to the address of browser 1
enjoy!

[ Reply to This | # ]
Automatically send a TinyURL from Safari via Mail.app
Authored by: luhmann on Thu, Feb 10 2005 at 6:50AM PST
Thanks, and here is one which will put the title of the page in the subject header and the body of the message.

-- ####################
-- # -- eMail tinyURL.scpt --
-- # script to automagically get
-- # and paste a tinyURL from
-- # the active Safari window
-- # into Mail.app.
-- # -- by nekvas 2005
-- # -- http://www.macosxhints.com/article.php?story=200502042003188
-- ####################

-- get the url
tell application "OmniWeb"
set bigURL to the address of browser 1
set theTitle to the name of browser 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:theTitle, content:(theTitle & return & return & "<" & tinyURL & ">")}
end tell

[ Reply to This | # ]
Automatically send a TinyURL from Safari via Mail.app
Authored by: philcozz on Sat, Feb 19 2005 at 11:53AM PST
Hi,

Anyway to modify this script so that it takes an OmniWeb page and sends the tinyURL to Entourage?

Thanks...

[ Reply to This | # ]
Automatically send a TinyURL from Safari via Mail.app
Authored by: philcozz on Sat, Feb 19 2005 at 4:27PM PST
Actually, I was able to modify it to go from OmniWeb to Entourage... At least this worked for me.

-- ####################
-- # -- eMail tinyURL.scpt --
-- # script to automagically get
-- # and paste a tinyURL from
-- # the active Safari window
-- # into Mail.app.
-- # -- by nekvas 2005
-- # -- http://www.macosxhints.com/article.php?story=200502042003188
-- ####################

-- get the url
tell application "OmniWeb"
set bigURL to the address of browser 1
set theTitle to the name of browser 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 "Microsoft Entourage"
activate
set MyMessage to make new draft window with properties ¬
{subject:theTitle, content:tinyURL}
end tell

[ Reply to This | # ]
Automatically send a TinyURL from Safari via Mail.app
Authored by: jaysoffian on Fri, Feb 11 2005 at 9:16AM PST

Two things:

  1. You can use http://tinyurl.com/api-create.php?url= as your URL and you get back just the tinyurl, so you can simplify your script quite a bit.

  2. This seemed like a good excuse to learn some more Cocoa, so I wrote a TinyURL Service. You can download it here:

    http://www.soffian.org/downloads/TinyURLService.service.zip

    Download it and place TinyURLService.service under ~/Library/Services and then logout/login. You can then select a URL in an editable text field and select Services -> TinyURL (command-shift-2) and it will get replaced with a tinyurl. Also, if you select a tinyurl, it will get replaced with the long form.

    Source code is available for the curious.

j.



[ Reply to This | # ]
Automatically send a TinyURL from Safari via Mail.app
Authored by: jaysoffian on Fri, Feb 11 2005 at 3:01PM PST
And here's a simplfied version:

-- get the url
tell application "Safari"
	set bigURL to the URL of document 1
	set theTitle to the name of document 1
end tell

-- build the command for curl...quoting the url
set curlCMD to ¬
	"curl --stderr /dev/null \"http://tinyurl.com/api-create.php?url=" & bigURL & "\""

-- run the script and get the result
set tinyURL to do shell script curlCMD

-- 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:theTitle, content:(return & theTitle & ":" & return & tinyURL & return & return)}
end tell


[ Reply to This | # ]
Using Perl packages
Authored by: mmacho on Wed, Jan 17 2007 at 1:45AM PST
The Terminal way (easy also for calling from AppleScript, etc). It can be use via scrapbook (copy/tinyurl.pl/paste) (as I mostly do) or via command arguments:
#!/usr/bin/env perl
#
# tinyurl.pl
#
# juanfc 2006-06-30
#
# 
use WWW::Shorten::TinyURL;
use WWW::Shorten 'TinyURL';

if (!@ARGV) {
    $small = makeashorterlink(`pbpaste`);
    system("echo -n $small | pbcopy" );
    print "$smalln";
} else {
    foreach $a (@ARGV) {
        print makeashorterlink($a), "n";
    }
}


[ Reply to This | # ]
Automatically send a TinyURL from Safari via Mail.app
Authored by: DougAdams on Sat, Apr 26 2008 at 2:32PM PDT
I modified this script to ask for an URL in a display dialog then display the TinyURL in a second dsiplay dialog, which you can copy from:

-- get the url
set bigURL to text returned of (display dialog "Enter URL to make Tiny:" default answer "")

-- 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
display dialog "Here's the TinyURL:" default answer tinyURL

---
Doug's AppleScripts for iTunes
dougscripts.com

[ Reply to This | # ]