How to use LaunchBar for Twitter (with "from LaunchBar")

Sharing and discussing custom scripts for LaunchBar

How to use LaunchBar for Twitter (with "from LaunchBar")

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

There are already some entries about applescripts to use LaunchBar for Twitter.
In this entry I want to give you some instructions how to install and use an applescript as a LaunchBar Action.

1. Copy the following code

Code: Select all
--  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 by @ptujec to work with LaunchBar
-----------------------------------------------------------------------


-- 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")
      return nothing
   end if
   
   --do tweetescape
   set tweet_new to tweetescape(tweet)
   
   -- take logininformation from keychain
   tell application "Keychain Scripting"
      set twitter_key to first Internet key of current keychain whose server is "twitter.com"
      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 ("source=launchbarat&status=" & tweet_new)
   set results to do shell script "curl --user " & twitter_login & " --data-binary " & twitter_status & " http://twitter.com/statuses/update.json"
   
   -- display dialog results
   my growlRegister()
   -- you can change "Tweet" into a diffent text e.g. "Zwitscher"
   growlNotify("Tweet", tweet)
   
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
using terms from application "GrowlHelperApp"
   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)
      tell application "GrowlHelperApp"
         notify with name "Alert" title grrTitle description grrDescription application name "Tweet"
      end tell
   end growlNotify
end using terms from


2. Open Script Editor ("/Applications/AppleScript/Script Editor.app")

3. Paste the code into the empty window of Script Editor. Save it as "Tweet" in the LaunchBar Actions Folder ("~/Library/Application Support/LaunchBar/Actions")

4. Restart LaunchBar

5. Tweet!
Now invoke LaunchBar and start typing "TWEET" until it comes up. (You can asign a abbreviation like a simple "T" with cmd+alt+A for the next time) Than hit the spacebar and write your Tweet. Press return.
And that should be it. Its a very fast way to post a tweet.

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.

Have fun!
Last edited by ptujec on Thu Dec 17, 2009 12:32 pm, edited 17 times in total.
ptujec
 
Posts: 187
Joined: Fri Dec 19, 2008 10:36 am

Part to show "from Launchar" in Tweet

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

LaunchBar got registered as a source for Twitter.

This is the relevant code to show "from LaunchBar" in your Tweets:

Code: Select all
set twitter_status to quoted form of ("source=launchbarat&status=" & tweet)


Its already included in the code above. So enjoy!
Last edited by ptujec on Thu Jun 04, 2009 10:27 am, edited 3 times in total.
ptujec
 
Posts: 187
Joined: Fri Dec 19, 2008 10:36 am

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

*please delete*
Last edited by ptujec on Thu Jun 04, 2009 10:26 am, edited 3 times in total.
ptujec
 
Posts: 187
Joined: Fri Dec 19, 2008 10:36 am

Postby more.said.then... » Fri Feb 13, 2009 5: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!
more.said.then...
 
Posts: 1
Joined: Fri Feb 13, 2009 4:46 am

Postby ptujec » Fri Feb 13, 2009 12: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
 
Posts: 187
Joined: Fri Dec 19, 2008 10:36 am

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

This is kind of a one-more-thing: http://is.gd/jHzD

Now you can combine this with the tiny URL script (http://is.gd/iIRg)!

Create a tiny URL and tweet it in just 3 or 4 steps:

1) select URL with LaunchBar (Instant Send)
2) hit "tt"
3) ... add some additional words to the tweet
4) hit ↩

or:
1) run "TinyAndTweet" script (it will take the URL in Safaris frontwindow)
3) ... add some additional words to the tweet
4) hit ↩
Last edited by ptujec on Mon Feb 16, 2009 5:43 pm, edited 3 times in total.
ptujec
 
Posts: 187
Joined: Fri Dec 19, 2008 10:36 am

Postby xanatos » Mon Feb 16, 2009 11:04 am

it would be nice if a script could return a string to LB like the compress functions return a path to a file
xanatos
 
Posts: 8
Joined: Sun Feb 15, 2009 12:20 pm

Postby ptujec » Mon Feb 16, 2009 2: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.
ptujec
 
Posts: 187
Joined: Fri Dec 19, 2008 10:36 am

Postby norbert » Mon Feb 16, 2009 3: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"
norbert
Objective Development
Objective Development
 
Posts: 538
Joined: Thu Nov 09, 2006 5:30 pm

Postby ptujec » Mon Feb 16, 2009 3: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 4:26 pm, edited 1 time in total.
ptujec
 
Posts: 187
Joined: Fri Dec 19, 2008 10:36 am

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

sound's good, I will give it a try in my script
xanatos
 
Posts: 8
Joined: Sun Feb 15, 2009 12:20 pm

Postby xanatos » Mon Feb 16, 2009 9: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?
xanatos
 
Posts: 8
Joined: Sun Feb 15, 2009 12:20 pm

Postby bd1121 » Tue Feb 24, 2009 7: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!
bd1121
 
Posts: 2
Joined: Tue Feb 24, 2009 7:47 pm

Postby ptujec » Tue Feb 24, 2009 11:12 pm

bd1121 wrote: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!


found s.th. here:
http://chucker.me/2007/08/06/more-statu ... g-goodness
... but it doesn't work yet. Thats how far I got:
http://pastie.org/399064
ptujec
 
Posts: 187
Joined: Fri Dec 19, 2008 10:36 am

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

Postby no-username » Fri Apr 10, 2009 10: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.
no-username
 
Posts: 33
Joined: Thu Mar 19, 2009 3:31 am

Next

Return to LaunchBar Scripts

Who is online

Users browsing this forum: No registered users and 1 guest