LaunchBar Script: Create bit.ly

I recently created and published a LaunchBar Action to create and copy a bit.ly URL to the clipboard and today I wanted to use the URL in a SMS, a new script would be needed to display the new shortened URL.

Not a big change from my first script but still worth publishing, in this version I display and copy the URL to the clipboard, download here.

on handle_string(theURL)

-- add scheme prefix if missing
set _firstColon to offset of ":" in theURL
set _firstSlash to offset of "/" in theURL
if (_firstColon = 0 or _firstSlash < _firstColon) then
set theURL to "http://" & theURL
end if
-- Process and encode URL
set theURL to do shell script "/usr/bin/python -c 'import sys, urllib; print urllib.quote(sys.argv[1])' " & quoted form of theURL
-- Create bit.ly
set login to "YOOURUSERNAME"
set apiKey to "YOURAPIKEY"
set bitlyURL to "http://api.bit.ly/shorten?version=2.0.1&longUrl=" & theURL & "&login=" & login & "&apiKey=" & apiKey & ""
set results to do shell script "curl " & quoted form of bitlyURL & " | grep shortUrl | awk '{print $2}' | sed 's/[\",]//g'"
-- Copy to clipboard and display
tell application "LaunchBar"
perform action "Copy" with string results
display in large type results
end tell

end handle_string

Again replace "YOURUSERNAME" and "YOURAPIKEY" with your own details and install the action by placing the file in ~/Library/Application Support/LaunchBar/Actions.

If you do not want to copy the URL as well remove the line “perform action "Copy" with string results".

3 Responses to LaunchBar Script: Create bit.ly
  1. [...] I did have a LaunchBar action to create bit.ly links that will work perfectly fine with bitly.pro howeve... mattytemple.com/2010/05/launchbar-action-create-short-url-with-yourls
  2. Sandro Reply

    Hi there,

    I wanted to see if there was an updated version of this script, newer than 2010. I have tried the script posted above in Launchbar and, while the bit.ly link is created, it is not copied to the clipboard. I “0″ flashes quickly on-screen and that is copied to the clipboard instead.

    Thanks,

    ~Sandro Munoz

    • Matt Reply

      Hi Sandro,

      This is the latest version at the moment but thanks for letting me know about this problem I will look into it and provide a fix probably over the weekend. I would normally do it sooner but I’m in the middle of a big server move this week.

Leave a Reply

Your email address will not be published. Please enter your name, email and a comment.

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>