How to use LaunchBar for Twitter

Sharing and discussing custom actions for LaunchBar
ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

How to use LaunchBar for Twitter

Postby ptujec » Fri Jan 09, 2009 4:48 pm

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!
Last edited by ptujec on Thu Jan 13, 2011 9:58 pm, edited 27 times in total.

ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

Part to show "from Launchar" in Tweet

Postby ptujec » Tue Jan 13, 2009 11:52 am

-- this reply contained outdated information so I deleted it --
Last edited by ptujec on Mon Jan 03, 2011 11:55 pm, edited 4 times in total.

ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

Postby ptujec » Tue Feb 10, 2009 10:55 pm

-- this reply contained outdated information so I deleted it --
Last edited by ptujec on Mon Jan 03, 2011 11:55 pm, edited 4 times in total.

more.said.then...
Posts: 1
Joined: Fri Feb 13, 2009 5:46 am

Postby more.said.then... » Fri Feb 13, 2009 6:03 am

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!

ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

Postby ptujec » Fri Feb 13, 2009 1:46 pm

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.

ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

Postby ptujec » Sun Feb 15, 2009 10:45 pm

-- this reply contained outdated information so I deleted it --
Last edited by ptujec on Mon Jan 03, 2011 11:56 pm, edited 4 times in total.

xanatos
Posts: 8
Joined: Sun Feb 15, 2009 1:20 pm

Postby xanatos » Mon Feb 16, 2009 12:04 pm

it would be nice if a script could return a string to LB like the compress functions return a path to a file

ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

Postby ptujec » Mon Feb 16, 2009 3:37 pm

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.

norbert
Objective Development
Objective Development
Posts: 648
Joined: Thu Nov 09, 2006 6:30 pm

Postby norbert » Mon Feb 16, 2009 4:07 pm

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"

ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

Postby ptujec » Mon Feb 16, 2009 4:30 pm

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.
Last edited by ptujec on Mon Feb 16, 2009 5:26 pm, edited 1 time in total.

xanatos
Posts: 8
Joined: Sun Feb 15, 2009 1:20 pm

Postby xanatos » Mon Feb 16, 2009 4:43 pm

sound's good, I will give it a try in my script

xanatos
Posts: 8
Joined: Sun Feb 15, 2009 1:20 pm

Postby xanatos » Mon Feb 16, 2009 10:39 pm

is there a way to enter text into the text field which will be displayed eg when executing a shell command from LB?

bd1121
Posts: 2
Joined: Tue Feb 24, 2009 8:47 pm

Postby bd1121 » Tue Feb 24, 2009 8:53 pm

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!

ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

Postby ptujec » Wed Feb 25, 2009 12:12 am

-- this reply contained outdated information so I deleted it --
Last edited by ptujec on Mon Jan 03, 2011 11:57 pm, edited 1 time in total.

no-username
Rank 1
Rank 1
Posts: 36
Joined: Thu Mar 19, 2009 4:31 am

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

Postby no-username » Fri Apr 10, 2009 11:18 am

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.


Return to “LaunchBar Actions”

Who is online

Users browsing this forum: No registered users and 0 guests