Create custom Adjix short URLs with Alfred

Alfred.app Logo Although I use it all the time it turns I haven't written here about Adjix. There is one mention in some issues but nothing that spells out just how awesome it is. The short version is Adjix is hands down the single best URL shortener out there. While it deserves it's own post suffice it to say you can use its power and still retain a copy of your links on your own S3 drive. Future proofing at its best.

But this post isn't about that. It's about using your own custom domain and setting up a URL shortener that works from Alfred. Alfred is itself another awesome tool that deserves yet another post. Inspired by a post on Dirt Don I set out to create a url shortening shortcut. (Recursion is encouraged).

So based on this post I setup a quick shell script shortcut in Alfred. The properties end up looking something like this:

Title: Shorten URL
Description: Shorten a URL and copy to clipboard
Keyword: sl

curl "http://api.adjix.com/shrinkLink?url={query}&partnerID=xxxxxMyPartnerIDxxxxxx&tokenOnly=yes" | awk 'BEGIN { FS = "!" }; { print "http://shorturl.me/" $1 }' | tr -d '\n' | pbcopy

This works as expected and after typing "sl http://example.com" into the Alfred window a short link is copied to the clipboard. And all is well with the world. Almost.

It's almost well with the world because it could be better. It turns out I already have a database of short links. Sure there's the filesystem on my S3 storage but I have a more immediately accessible database. It is the same database that powers this website. And that database has a collection of URLs that I've shortened over time and serves as another sort of record. Wouldn't it be nice to connect the two?

The Shorten module is the powerhouse of Drupal and URL shortening. If you use Drupal and you need to make short URLs for any reason it should be your first choice. So I thought well I can create a callback for Shorten that provides a simple web service ala the other redirection tools. And certainly I could do that. But that's when it hit me that I already have the tools I needed and the script would be a short one. A little Drush is all that's needed.

My desktop is already setup with drush and a site alias for my site. With this knowledge the above code became:

drush @joshuabrauer.prod ev "print (shorten_url('{query}'));" | pbcopy

There are several advantages including that it gets stored in my database. In addition I can customize the rules for how the shortener works on my site should I need to and there's no need to hard-code the shortener domain in the script.

Of course nothing about these scripts is particularly unique to Alfred. They would work just as well as shell scripts on pretty much any operating system. Soon I'll write more about how I am using Drupal more and more through tools other than web browsers.

Comments

Jan
4
2012

bugging

by alfiesaden

hello - is it just me !! can any one explain why when i type in the bing browser "joshuabrauer.com" i get a different site yet whe i type it in google its ok? could this be a bug in my system or is any one else having same probs ?
alf

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Link to Amazon products with: [amazon product_id inline|full|thumbnail|datadescriptor]. Example: [amazon 1590597559 thumbnail] or [amazon 1590597559 author]. Details are on the Amazon module handbook page.
  • Twitter-style @usersnames are linked to their Twitter account pages.
  • Twitter-style #hashtags are linked to search.twitter.com.
  • Allowed HTML tags: <a> <b> <dd> <dl> <dt> <i> <li> <ol> <u> <ul><p> <img> <strong><em><sup><div><fn><h1><h2><h3><h4><blockquote><img style="">
  • Use [fn]...[/fn] (or <fn>...</fn>) to insert automatically numbered footnotes.
  • You may insert videos with [video:URL]
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically. (Better URL filter.)
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options