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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s