Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the '10.6: Create a URL shortening Service' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.6: Create a URL shortening Service
Authored by: iandol on Sep 15, '09 02:59:50PM
The Applescript is such a horrible hack and requires a specific browser to be open. has an open API, and a much more elegant solution is to use Run Shell Script in Automator, set the shell to /usr/bin/ruby, then use this more elegant ruby code:

#!/usr/bin/env ruby
require 'uri'
require 'net/http'

uri = STDIN.gets(nil).strip.delete("\n\r")
unless uri.empty?
    escaped_uri = URI.escape("{uri}")
    STDOUT << Net::HTTP.get_response(URI.parse(escaped_uri)).body
  rescue URI::InvalidURIError
    # Do nothing.
If you want to use, then replace the escaped_uri line with this:

escaped_uri = URI.escape("{uri}")

[ Reply to This | # ]