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 firstname.lastname@example.org 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
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
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:
- Create a new snippet (command-N) and paste the following AppleScript in the “Content” box:
- 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.
- 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”.
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
Here’s what it should look like:
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:
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à:
That’s a way easier URL to post on Twitter!
Pingback: My First Article Is Up at LiveDigitally.com
Pingback: SmileOnMyMac Blog » Blog Archive » TextExpander: Nice AppleScript Shortcut for bit.ly
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
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)
Pingback: Rawkes Weekly – 27 July 2008 » Captain's Blog » Rawkes
How about http://sn.vc? They allow to preview the original links before redirected. For me, it’s useful as to prevent mislead.
Pingback: Downshift: The Second Gear Blog » Blog Archive » Our Toolbox: TextExpander
Pingback: Quickly Extract a Shortened URL for Anything on the iTunes App Store | MacMembrane
Pingback: Add Bit.ly URL Shortening To Quicksilver | Lifehacker Australia
Pingback: Add Bit.ly URL Shortening to Quicksilver [How To] · TechBlogger
This doesn’t seem to work anymore. Has anyone tried this code since Bitly.com changed things around with their service and tracking links?