Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,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 2.00 / 5
  You rated: 1 / 5 (4 votes cast)
 
[20,828 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 whoever posted them. This site is not responsible for what they say.
Automatically send a TinyURL from Safari via Mail.app
Authored by: stift on Feb 08, '05 10:49:23AM

;-) for the link



[ Reply to This | # ]
Automatically send a TinyURL from Safari via Mail.app
Authored by: daybrother on Feb 08, '05 11:04:07AM
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 Feb 08, '05 11:40:05AM
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 Feb 08, '05 12:15:41PM

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 Feb 08, '05 12:19:31PM

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 Feb 08, '05 12:34:38PM

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 Feb 08, '05 05:50:56PM

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 Feb 11, '05 11:09:59AM
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 Feb 11, '05 11:18:34AM

Oops, I posted much too late - obviously others already posted this.



[ Reply to This | # ]
keyword
Authored by: spatfield on Feb 08, '05 07:12:15PM

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 Feb 08, '05 07:53:13PM

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 Feb 09, '05 10:26:42AM

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 Feb 09, '05 05:15:58PM

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 Feb 09, '05 11:53:31PM
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 Feb 10, '05 06:50:34AM

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 Feb 19, '05 11:53:01AM

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 Feb 19, '05 04:27:13PM

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 Feb 11, '05 09:16:42AM

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 Feb 11, '05 03:01:22PM
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: juanfal on Jan 17, '07 01:45:03AM
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 Apr 26, '08 02:32:49PM
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 | # ]