• About

LIVEdigitally

How-to: Automatic URL Shortening with Bit.ly and TextExpander

Posted on July 23, 2008 by Guest Contributor

Hi, my name is jonathanpberger and I’ll be covering all sorts of nerdy topics here on LiveDigitally. Got comments? Questions? Rants? You can drop me a line at jpb@livedigitally.com or see what else I’m up to on my Twitter feed, my homepage, or my tumbleblog.

One of my can’t-live-without-it time-and-keystroke-saving apps (TextExpander) got bumped to version 2.3 today. It’s a minor update: a few bug-fixes and a new snippet group for Accented Words (like “rosé”, “olé”, “sauté”, or “jalapeño”). But I got to playing around, and saw a cool video demonstrating how to use TextExpander for another time-and-keystroke-saver: URL-Shortening.

URL-Shortening may not seem like a big deal, but it comes in handy when you’re dealing with space restrictions (like Twitter’s 140 character-limit), you want to tidy up some messy links, or you’re trying to RickRoll someone. It’s one of those possibly-extraneous activities that makes life a tiny little bit easier, but only when it’s effortless to employ. Enter TextExpander.

Jack-Daniyel Strong has a great tip for shortening URLs using TinyURL, TextExpander, and Applescript. After setting it up, you can shorten URLs by

1) copying the URL to the clipboard, and 2) typing a preset abbreviation. It’s that easy.

I’ve adapted his technique for the new kid on the URL-shortening block, Bit.ly (which everyone is gushing over), and which provides a host of neat features like History, Click/Referrer tracking, thumbnails, mirroring, and best of all, a robust API.

I’ve written briefly about TextExpander in the past, but allow me to go on at greater length: TextExpander is frickin’ AWESOME. It provides system-wide text abbreviations which I use literally tens or even hundreds of times each day. Common typos? Fixed. “Teh” turns into “the” automatically, every time, in any application. Common abbreviations or boilerplate text? Use a few letters to spit out long, commonly-used strings of text. I use “jonathanpberger” as my account name on pretty much every public web service around: Twitter, Flickr, Del.icio.us, Google account, etc. I must type those 15 characters a hundred times a day—except I don’t type them. I type “jjpb”, and they’re filled in automatically.

How about HTML or CSS? Not only can I type “,a” (that’s “comma-A”) and get

<a href=""></a>

or type “,img” (that’s “comma-i-m-g”) for

<img src="" alt="" width="" height="" border="0" />

but the cursor will return to the spot where I need to start typing: between the quotes after the “href=""” or “src=""”.

What’s more, SmileOnMyMac (the company responsible for TextExpander) provides libraries of useful snippets like HTML, CSS, common misspellings, and more, all of which you can install with a click.

Ok, enough gushing. This isn’t an infomercial. What we’re here for today is TextExpander’s AppleScript support. Here we go:

  1. Create a new snippet (command-N) and paste the following AppleScript in the “Content” box:
  2. 	set the ClipURL to (the clipboard as string)
    
    	ignoring case
    		if ((characters 1 through 4 of ClipURL as string) is not "http") then
    			return "Malformed URL."
    		else
    			set curlCMD to ¬
    				"curl --stderr /dev/null "http://bit.ly/api?url=" & ClipURL & """
    
    			-- Run the script and get the result:
    			set tinyURL to (do shell script curlCMD)
    
    			return tinyURL
    		end if
    	end ignoring
  3. Above the box, you’ll want to change “Content: Plain Text” to “Content: AppleScript” so that we execute the script instead of replacing our text with the raw code.
  4. Set the Abbreviation. I like the standard TextExpander convention of doubling the first letter (I use the default “ttime” for a timestamp), so I use “bbit”.

Here’s what it should look like:

Setting up the Bit.ly AppleScript in TextExpander

All done. Now let’s say (hypothetically) you have a cousin who’s researching family genealogy on her summer break. Maybe (if you’re a cousin of mine) she’ll have sent you a link to an image of the immigration record on Ellis Island that brought your family to this country back in 1908. It might have a URL that looks like this:

http://www.ellisisland.org/EIFile/popup_weif_5a.asp?src=%2Fcgi%2Dbin%2Ftif2gif%2Eexe%3FT%3D%5C%5C%5C%5C192%2E168%2E4%2E227%5C%5Cimages%5C%5CT715%2D1081%5C%5CT715%2D10810827%2ETIF%26S%3D%2E5&pID=101759060124&name=Beile%26nbsp%3BMinowitz&doa=Mar+07%2C+1908&port=Liverpool&line=0019

Now that we’ve got the Bit.ly AppleScript set up, all we have to do is select that painfully long URL, copy it to the clipboard (Edit>Copy or command-C), and type “bbit”. Voilà:

http://bit.ly/4swZ2G

That’s a way easier URL to post on Twitter!

Share this:

  • Email
  • Facebook
  • LinkedIn
  • Twitter
  • Reddit

Related

Posted in General, Web/Internet | Tags: how-to, tech, URL | 10 Comments
« Wireless HDTV R&D Update: Tons of Spending, Tiny Market
12seconds.tv launches in alpha »

10 thoughts on “How-to: Automatic URL Shortening with Bit.ly and TextExpander”

  1. Pingback: My First Article Is Up at LiveDigitally.com

  2. Pingback: SmileOnMyMac Blog » Blog Archive » TextExpander: Nice AppleScript Shortcut for bit.ly

  3. someone says:
    July 25, 2008 at 5:52 pm

    If you’re truncating the URL of your front Safari window, you can cut out the selecting/copying steps like this:

    tell application "Safari"

    set PageURL to URL of front document

    end tell

    set curlCMD to ¬
    "curl --stderr /dev/null "http://bit.ly/api?url=" & PageURL & """

    -- Run the script and get the result:
    set bitlyURL to (do shell script curlCMD)

    return bitlyURL

    Reply
  4. Pingback: Rawkes Weekly – 27 July 2008 » Captain's Blog » Rawkes

  5. Cristine says:
    August 15, 2008 at 9:09 am

    How about http://sn.vc? They allow to preview the original links before redirected. For me, it’s useful as to prevent mislead.

    Reply
  6. Pingback: Downshift: The Second Gear Blog » Blog Archive » Our Toolbox: TextExpander

  7. Pingback: Quickly Extract a Shortened URL for Anything on the iTunes App Store | MacMembrane

  8. Pingback: Add Bit.ly URL Shortening To Quicksilver | Lifehacker Australia

  9. Pingback: Add Bit.ly URL Shortening to Quicksilver [How To] · TechBlogger

  10. skillet says:
    November 2, 2012 at 12:43 pm

    This doesn’t seem to work anymore. Has anyone tried this code since Bitly.com changed things around with their service and tracking links?

    Reply

Leave a comment Cancel reply

Your email address will not be published. Required fields are marked *

About

Jeremy Toeman is a seasoned Product leader with over 20 years experience in the convergence of digital media, mobile entertainment, social entertainment, smart TV and consumer technology. Prior ventures and projects include CNET, Viggle/Dijit/Nextguide, Sling Media, VUDU, Clicker, DivX, Rovi, Mediabolic, Boxee, and many other consumer technology companies. This blog represents his personal opinion and outlook on things.

Recent Posts

  • Back on the wagon/horse?
  • 11 Tips for Startups Pitching Big Companies
  • CES 2016: A New Role
  • Everything I Learned (So Far) Working For a Huge Company
  • And I’m Back…

Archives

Pages

  • About

Archives

  • January 2019
  • April 2016
  • January 2016
  • December 2015
  • June 2015
  • May 2015
  • April 2015
  • March 2015
  • February 2015
  • January 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • August 2014
  • June 2014
  • May 2014
  • April 2014
  • March 2014
  • January 2014
  • December 2013
  • September 2013
  • August 2013
  • July 2013
  • May 2013
  • February 2013
  • January 2013
  • December 2012
  • October 2012
  • September 2012
  • August 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • June 2011
  • March 2011
  • February 2011
  • January 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008
  • December 2007
  • November 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007
  • February 2007
  • January 2007
  • December 2006
  • November 2006
  • October 2006
  • September 2006
  • August 2006
  • July 2006
  • June 2006
  • May 2006
  • April 2006
  • March 2006
  • February 2006
  • January 2006
  • December 2005
  • November 2005
  • October 2005
  • September 2005
  • August 2005
  • July 2005
  • June 2005
  • May 2005
  • April 2005
  • March 2005
  • February 2005
  • January 2005
  • December 2004
  • November 2004
  • October 2004
  • September 2004

Categories

  • Convergence (81)
  • Gadgets (144)
  • Gaming (19)
  • General (999)
  • Guides (35)
  • LD Approved (72)
  • Marketing (23)
  • Mobile Technology (111)
  • Networking (22)
  • No/Low-tech (64)
  • Product Announcements (85)
  • Product Reviews (109)
  • That's Janky (93)
  • Travel (29)
  • Video/Music/Media (115)
  • Web/Internet (103)

WordPress

  • Log in
  • WordPress

CyberChimps WordPress Themes

© LIVEdigitally
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.