Return to Snippet

Revision: 40309
at January 29, 2011 14:45 by insanedreamer


Initial 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/v3/shorten?login=yourlogin&apiKey=yourapikey&longUrl=#{uri}&format=txt")
    STDOUT << Net::HTTP.get_response(URI.parse(escaped_uri)).body
  rescue URI::InvalidURIError
    # Do nothing.
  end
end

Initial URL


Initial Description
Place script into Automator (select "Run Shell Script" choose /usr/bin/ruby as the shell).

You'll need to create a bit.ly account which will give you your API key for authentication.

Initial Title
OSX service to shorten URLs

Initial Tags
ruby, osx

Initial Language
Ruby