LaunchBar Action: Create

I recently created and published a LaunchBar Action to create and copy a 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
	set login to "YOURUSERNAME"
	set apiKey to "YOURAPIKEY"
	set bitlyURL to "" & theURL & "&login=" & login & "&apiKey=" & apiKey & "&format=txt"
	set results to do shell script "curl " & quoted form of bitlyURL

        -- Copy to clipboard and display
	tell application "LaunchBar"
		perform action "Copy" with string results
		display in large type results
	end tell
end handle_string

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.

I have provide this action for free, but if you find it useful please make a small donation

  • #1 written by Stephan Lamprecht
    about 1 week ago


    thank you for this script. unfortunately it doesnt work for me. Though Username and Api-Key are correct, the script returns always a zero and nothing in the clipboard. Bitly shows me, that i has shortened the url. any idea?


  • #2 written by Matt
    about 1 week ago

    @Stephan Lamprecht:

    Hmm, I have no idea at the moment, my first guess would be a small change to the API. I’ll start working on that right away

  • #3 written by Matt
    about 1 week ago

    @Stephan Lamprecht:

    Thank you Stephan, I have now updated the script to use the new version of the API and it now works as advertised.

  • #4 written by Stephan Lamprecht
    about 1 week ago

    Hi, Matt,

    cool. I just tested it and it works great!

    Thank you so much. Guys like you are the reasons why i love to use macs.


No trackbacks yet.