Most of us these days utilize services such as bit.ly in order to shorten URLs. You can do this by using browser bookmarklets, websites, or certain apps such as TweetDeck which can shorten your links automatically when posting to Twitter. However, there is a quick and easy way to enable link shortening from within any app using Automator.
Once you have completed the steps below, you will be able to shorten any URL from any application’s menu using the bit.ly API. This one only works for users running OS X 10.6 or later.
1. First open Automator by navigating to Applications>Automator. Double click the Service icon to create a new script. If the screen in the image above does not appear when launching automator, select File>New.
2. Two drop down lists at the top of Automator should be set to “Service receives selected URLs in any application. The “Replaces selected text” checkbox should remained unchecked.
3. From the left hand panel, navigate to Library>Utilities>Run AppleScript and drag Run AppleScript into your project on the right.
4. Now replace the default Run AppleScript text with the following:
on run {input}
set inputResult to (input as string)
ignoring case
if (((characters 1 thru 4 of inputResult) as string) is not equal to “http”) then
display dialog “Invalid URL”
else
set curlCMD to “curl –stderr /dev/null \”http://bit.ly/api?url=” & input & “\””
set tinyURL to (do shell script curlCMD)
return tinyURL
end if
end ignoring
end run
5. Now, navigate to Library>Utilities> in the left panel and drag Copy to Clipboard underneath the Run AppleScript action in your workflow on the right.
6. Now, save your Automator Service and name it something you will recognize, such as “Shorten URL”.
You are now ready to use the Service. Highlighting a URL and right clicking it will now provide you with “Shorten URL” (or whatever you named your Service) in the corresponding drop down menu. Clicking it will automatically contact the Bit.ly API and copy the shortened URL to your clipboard, ready to paste as needed. You can of course also create a keyboard shortcut for the Service in System Preferences>Keyboard>Keyboard Shortcuts>Services.
[gigaom]