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


Click here to return to the '10.6: Create a tri.im 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 tri.im 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. Tr.im 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?
  begin
    escaped_uri = URI.escape("http://api.bit.ly/shorten?version=2.0.1&longUrl=#{uri}")
    STDOUT << Net::HTTP.get_response(URI.parse(escaped_uri)).body
  rescue URI::InvalidURIError
    # Do nothing.
  end
end
If you want to use tinyurl.com, then replace the escaped_uri line with this:

escaped_uri = URI.escape("http://tinyurl.com/api-create.php?url=#{uri}")


[ Reply to This | # ]