Page 1 of 3

How to use LaunchBar for Twitter

Posted: Fri Jan 09, 2009 4:48 pm
by ptujec
This entry will give you some instructions how to install and use an applescript as a LaunchBar action for Twitter.com. Unfortunately you need to set up an supertweet account and create an new keychain entry with your supertweet credentials first.
Supertweet will work as a proxy to oAuth. OAuth is required by Twitter for authentication.

Ok, here are the directions step by step:
1. Go to http://www.supertweet.net/ and set up an account.

2. Open Keychain Access.app ("/Applications/Utilities/Keychain Access.app") and create a new item (⌘N) with Name: http://www.supertweet.net; Account Name: YOUR SUPERTWEET USERNAME; Passwort: YOUR SECRET KEY.

3. Copy the following code (select all, copy)

Code: Select all

-- Tweet 
-- Last edited: 2011-01-13 by @Ptujec

--  This script was put together with the help of the following sources:
--  http://blog.codahale.com/2007/01/15/tweet-twitter-quicksilver/ by Coda Hale
--  http://i.grahamenglish.net/540/iquicktwitter-my-quicksilver-twitter-ichat-growl-hack/ by Graham English
--  http://www.leancrew.com/all-this/2009/02/url-shortening-scripts-fixed-i-think/ by @drdrang (fix for &ampersand issues)
--  put together and adapted to work with LaunchBar by @ptujec (also some tweaking to the Growl notifications)
--  http://github.com/kuroir/Launchbar-Twitter-Tools for supertweet fix
--  Keychain support by @aristidesfl

-----------------------------------------------------------------------


-- take string from LaunchBar
on handle_string(tweet)
   
   -- do wordcount
   if length of tweet > 140 then
      my growlRegister()
      growlNotify("Tweet too long", ("(" & length of tweet as text) & ") characters", 2)
      return nothing
   end if
   
   try
      --do tweetescape
      set tweet_new to tweetescape(tweet)
      
      -- take logininformation from keychain
      
      -- !!! You need a http://www.supertweet.net/ account, which will work as a proxy to oAuth.
      -- This will allow us to use this tool in a safer manner.
      --
      -- !!! You than need to create a new keychain entry with
      -- Name: http://www.supertweet.net/
      -- Account Name: YOUR SUPERTWEET USERNAME
      -- Passwort: YOUR SECRET KEY
      
      tell application "Keychain Scripting"
         set twitter_key to first Internet key of current keychain whose name is "www.supertweet.net"
         set twitter_login to quoted form of (account of twitter_key & ":" & password of twitter_key)
      end tell
      
      -- update twitter
      set twitter_status to quoted form of ("status=" & tweet_new)
      set results to do shell script "curl -u" & twitter_login & " -d" & twitter_status & " http://api.supertweet.net/1/statuses/update.xml"
      
      -- display dialog results
      my growlRegister()
      -- you can change "Tweet" into a diffent text e.g. "Zwitscher"
      growlNotify("Tweet", tweet, 0)
      
   on error e
      my growlRegister()
      growlNotify("Error", e, 2)
   end try
   
end handle_string

-- fix for &ampersand issues (by @drdrang)
on tweetescape(tweet)
   set cmd to "\nfrom urllib import quote\nprint quote(\"\"\"" & tweet & "\"\"\", \"/:\")\n"
   return (do shell script "python -c " & (quoted form of cmd))
end tweetescape

-- additional scripting for Growlnotificati
on growlRegister()
   tell application "GrowlHelperApp"
      register as application "Tweet" all notifications {"Alert"} default notifications {"Alert"} icon of application "Launchbar.app"
   end tell
end growlRegister
on growlNotify(grrTitle, grrDescription, grrPriority)
   tell application "GrowlHelperApp"
      notify with name "Alert" title grrTitle description grrDescription priority grrPriority application name "Tweet"
   end tell
end growlNotify


4. Open AppleScript Editor ("/Applications/Utilities/AppleScript Editor.app")

5. Paste the code into a new empty window. Than replace YOURNAME with your username and YOURKEY with your secret key from http://www.supertweet.net/.

6. Save the script as "Tweet" in the LaunchBar Actions Folder ("~/Library/Application Support/LaunchBar/Actions")

7. Tweet!
Invoke LaunchBar and start typing "TWEET" until it comes up. (You can assign a abbreviation like a simple "T" with cmd+alt+A for the next time) Than hit the spacebar and write your Tweet. Press return. You will be asked to allow keychain access when using it the first time.
And that should be it. Its a very fast way to post s.th. on Twitter.

Final words
If you are using Growl (http://www.growl.info/) you will get a notification with your Tweet, so you know your Tweet was successful submitted. If not you eventually need to delete the Growl related sections.
Have fun!

Part to show "from Launchar" in Tweet

Posted: Tue Jan 13, 2009 11:52 am
by ptujec
-- this reply contained outdated information so I deleted it --

Posted: Tue Feb 10, 2009 10:55 pm
by ptujec
-- this reply contained outdated information so I deleted it --

Posted: Fri Feb 13, 2009 6:03 am
by more.said.then...
Please keep up the good work and supplying source :mrgreen: . I had quit using launchbar for years and then I re-discovered LB5 with so much more functionality, hardest part is remembering each hotkey and "option" commands/keys.

With knowledgeable folks like yourselves coding scripts for private use or otherwise benefit the LB5 project. As a long time little snitch user I was happy to see both apps being developed. There are definitely some dry spells, when releases are far and few between, but good apps can cope and not lose customers.

That is where coders, whom can take advantage of applescript support help a great deal. I know you aren't getting paid for your hard work and the hours put in for it to be tweaked to near perfection. Man, I would be so happy to see you take your skills and open a little site selling your scripts or at least donation-ware. I'll fund projects lol.

Seriously though, would you ever be willing to try and code an applescript add-on for something specific? Of course, cash before source. If you would be willing to at least attempt or think about an idea or two or three that I have I would LOVE if you got in contact with me either through pm here or email through the board. Much love, have a great weekend I hope to hear from you. Thanks again!

Posted: Fri Feb 13, 2009 1:46 pm
by ptujec
more.said.then... wrote:Please keep up the good work and supplying source :mrgreen: . I had quit using launchbar for years and then I re-discovered LB5 with so much more functionality, hardest part is remembering each hotkey and "option" commands/keys.

With knowledgeable folks like yourselves coding scripts for private use or otherwise benefit the LB5 project. As a long time little snitch user I was happy to see both apps being developed. There are definitely some dry spells, when releases are far and few between, but good apps can cope and not lose customers.

That is where coders, whom can take advantage of applescript support help a great deal. I know you aren't getting paid for your hard work and the hours put in for it to be tweaked to near perfection. Man, I would be so happy to see you take your skills and open a little site selling your scripts or at least donation-ware. I'll fund projects lol.

Seriously though, would you ever be willing to try and code an applescript add-on for something specific? Of course, cash before source. If you would be willing to at least attempt or think about an idea or two or three that I have I would LOVE if you got in contact with me either through pm here or email through the board. Much love, have a great weekend I hope to hear from you. Thanks again!


What you write flatters me. But actually I'm only collecting pieces and putting them together. Seriously. Fair enough that I share the outcome.
If you follow the sources (mentioned in the script) you will get to the people who are doing the work.

Posted: Sun Feb 15, 2009 10:45 pm
by ptujec
-- this reply contained outdated information so I deleted it --

Posted: Mon Feb 16, 2009 12:04 pm
by xanatos
it would be nice if a script could return a string to LB like the compress functions return a path to a file

Posted: Mon Feb 16, 2009 3:37 pm
by ptujec
xanatos wrote:it would be nice if a script could return a string to LB like the compress functions return a path to a file


I agree ... but have no clue how to do that. Would like to be able to add words to it before tweeting though.

Posted: Mon Feb 16, 2009 4:07 pm
by norbert
xanatos wrote:it would be nice if a script could return a string to LB like the compress functions return a path to a file

Right now this can be accomplished with:

Code: Select all

tell application "LaunchBar" to set selection as text to "some text"

Posted: Mon Feb 16, 2009 4:30 pm
by ptujec
norbert wrote:
xanatos wrote:it would be nice if a script could return a string to LB like the compress functions return a path to a file

Right now this can be accomplished with:

Code: Select all

tell application "LaunchBar" to set selection as text to "some text"


... in this case:

Code: Select all

tell application "LaunchBar" to set selection as text to shortURL


Though thats nice I wish it would be possible to add text to it. Otherwise its of no use for Twitter.

Posted: Mon Feb 16, 2009 4:43 pm
by xanatos
sound's good, I will give it a try in my script

Posted: Mon Feb 16, 2009 10:39 pm
by xanatos
is there a way to enter text into the text field which will be displayed eg when executing a shell command from LB?

Posted: Tue Feb 24, 2009 8:53 pm
by bd1121
This is all very helpful! The script works great. Does anyone have a solution for posting status updates to Facebook in this same way?

Thanks!

Posted: Wed Feb 25, 2009 12:12 am
by ptujec
-- this reply contained outdated information so I deleted it --

Re: How to use LaunchBar for Twitter (with Source!)

Posted: Fri Apr 10, 2009 11:18 am
by no-username
I believe this script can only work if you have your login and pass stored in your keychain, which I do not. It seems to do nothing for me, no error, no tweet.