Saturday, January 22, 2011

Mac OS Hint: URL shortener. Tried it

Tried out an advice | found in Macworld (dec 2010). www.macworld.com/6634 It is a service for Automator to shorten an URL from any application to clipboard.
I wanted to use it with bit.ly, hoping to see URLs I shorten in my bit.ly history. That means, I needed to change the script  provided by the hint. 

I changed the RETURN part of script to 

return (do shell script "/usr/bin/curl 'http://api.bit.ly/v3/shorten?login=MY_LOGIN&apiKey=MY_API_KEY&longUrl=" & (item 1 of the input) & "'")

where MY_LOGIN is my bit.ly login name and MY_API_KEY - my bit.ly API key.
I got the service working well, but returning a bunch of useless text.

My mistake was using default response format (json). Ineeded plain text to paste.

return (do shell script "/usr/bin/curl 'http://api.bit.ly/v3/shorten?login=MY_LOGIN&apiKey=MY_API_KEY&longUrl=" & (item 1 of the input) & "&format=txt'")

The second attempt is just fine. The service works well.
Except Twitter app which shortens any URL it gets without asking me, making a quite long in comparison to bit.ly URL with t.co.

And now the key question: where in hell do you need shortened URLs except Twitter? As you see, in this blog I do not shorten URLs for you to se, where they are going to lead you...
Nice service for "Do it yourself", if you are trying it just for fun.

No comments: