Create short links with TextExpander and yourls

I want to type ghurl, and have TextExpander grab the URL in my clipboard, and replace it with my link-shortening service, running yourls.

  1. Grab your “secret signature token” from the Tools page in yourls.
  2. Create a shell script, short-url.sh in your ~/bin directory (or wherever). Yes, we could just drop this script into TextExpander, but it’d be nice to be able to use this script in other contexts.
    #!/bin/bash
    id="YOURLS_SECRET_TOKEN_HERE"
    curl --silent -o - "http://YOURLS_URL_HERE/yourls-api.php?signature=$id&action=shorturl&format=simply&url=$1" | 
       awk -F# '{gsub(/ /,"");print ($1) }'
    
  3. Create a new “Shell Script” snippet in TextExpander, which calls the script we just made:
    #!/bin/bash
    ~/bin/short-url.sh "%clipboard"
    
  4. Enjoy.

If you want to do this for the public link shortening services, like bit.ly, is.gd, or tinyurl, you should check out ttscoff‘s project on GitHub.