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:

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

Post by ptujec » Fri Apr 10, 2009 2:22 pm

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

sjk
Wizard
Wizard
Posts: 315
Joined: Thu Sep 13, 2007 9:46 pm
Location: Eugene
Contact:

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

Post by sjk » Wed Oct 14, 2009 6:39 pm

Try Twitter Support :: Frequently Asked Questions; this forum isn't a general help/support resource for Twitter.

donovanwatts
Posts: 1
Joined: Sun Feb 07, 2010 7:57 pm

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

Post by donovanwatts » Sun Feb 07, 2010 7:59 pm

Thanks so much for this. Most handy. And I appreciate your level of detail. For instance, telling us exactly where to save the file. Little details like that for a LaunchBar newbie are excellent.

asathomas
Posts: 1
Joined: Sun Feb 28, 2010 5:13 pm

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

Post by asathomas » Sun Feb 28, 2010 5:16 pm

I'm having issues with this, when i try to run the script I get a prompt saying Expected end of line but found “"”. and it focuses on

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)

It doesn't let me save it in it's current state.
Hope you can help out a complete launch bar noob here.
Thanks

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

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

Post by ptujec » Sun Feb 28, 2010 6:45 pm

asathomas wrote:I'm having issues with this, when i try to run the script I get a prompt saying Expected end of line but found “"”. and it focuses on

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)

It doesn't let me save it in it's current state.
Hope you can help out a complete launch bar noob here.
Thanks


Obviously you didn't selected the whole script. Use "Select All" to copy the whole script.
Image

aristidesfl
Rank 3
Rank 3
Posts: 120
Joined: Sat Feb 27, 2010 12:54 am

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

Post by aristidesfl » Tue Mar 02, 2010 4:33 am

Here is a working version of the script with word count, keychain, and a 17 long very fast url shortener u.nu

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
--  minor changes to convert urls to tiny versions by @ctwise (http://tedwise.com)
--  changes to work with u.nu.com instead of tiny url by aristidesfl
-----------------------------------------------------------------------


-- take string from LaunchBar
on handle_string(tweet)
   -- shorten urls
   set tweet to replace_http(tweet)
   
   -- do wordcount
   set wordcount to do shell script "echo " & quoted form of tweet & " | wc -c"
   set wordcount to do shell script "echo " & quoted form of wordcount & " | sed 's/^[    ]*//'"
   
   if wordcount as integer > 140 then
      -- notify when tweet contains more than 140 characters
      my growlRegister()
      growlNotify("Tweet too long", "(" & wordcount & ") 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 name is "twitter.com"
      set twitter_login to quoted form of (account of twitter_key & ":" & password of twitter_key)
   end tell
   
   my growlRegister()
   -- update twitter
   try
      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
      -- you can change "Tweet" into a diffent text e.g. "Zwitscher"
      growlNotify("Tweet sent", tweet)
   on error
      -- Display error message
      growlNotify("Error Tweeting.", "You have fucked up, try again.")
   end try
end handle_string

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

-- additional scripting for Growlnotification
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

-- This uses the built in splitting in AppleScript.
-- Most of the code just restores the delimiters.
on split(theText, splitText)
   set tid to AppleScript's text item delimiters
   set AppleScript's text item delimiters to splitText
   set theTextItems to text items of theText
   set AppleScript's text item delimiters to tid
   return theTextItems
end split

-- I tried the opposite of the split implementation but for some
-- reason it doesn't work reliably
on join(theList, joinText)
   set result to ""
   repeat with theToken in theList
      if length of result = 0 then
         set result to theToken
      else
         set result to result & joinText & theToken
      end if
   end repeat
   return result
end join

-- Send the url to tiny url for shortening
on shorten_url(theURL)
   set theURL to tweetescape(theURL)
   
   set curlCMD to ¬
      "curl --stderr /dev/null \"http://u.nu/unu-api-simple?url=" & theURL & "\""
   
   set results to do shell script curlCMD
   return results
end shorten_url

-- Find everything that looks like a URL and shorten it
-- The number 25 is the length of a tiny url, no point in
-- shortening a url if it's already below that.
on replace_http(theText)
   set tokens to split(theText, " ")
   set output to {}
   repeat with theToken in tokens
      if (theToken starts with "http://") and length of theToken > 17 then
         set the end of output to shorten_url(theToken)
      else if (theToken starts with "www.") and length of theToken > 17 then
         set the end of output to shorten_url(theToken)
      else
         set the end of output to theToken
      end if
   end repeat
   return join(output, " ")
end replace_http


If you want the same but that uses the tweeter icon in the growl notifications download here: http://hotfile.com/dl/30781444/05ea3a5/Tweet.scpt.html
(you have to put the script in the actions default folder and cannot rename it)

aristidesfl
Rank 3
Rank 3
Posts: 120
Joined: Sat Feb 27, 2010 12:54 am

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

Post by aristidesfl » Fri Mar 05, 2010 7:31 pm

this is applescript fot the macs

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

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

Post by ptujec » Thu Apr 29, 2010 12:46 pm

For some reason the script turned a bit slow, so it makes sense to run it in background. Just create a .plist file with the same name in the same folder (tweet.scpt = tweet.plist) and the following content:

Code: Select all

{
    RunInBackground = YES;
}

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

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

Post by ptujec » Fri Aug 06, 2010 8:23 am

markjay50 wrote:... Does anyone have a solution for posting status updates to Facebook in this same way?


Unfortunately not. But http://www.facebook.com/notifier works great.

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

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

Post by ptujec » Thu Sep 02, 2010 5:04 pm

-- this reply contained outdated information so I deleted it --
Last edited by ptujec on Tue Jan 04, 2011 12:01 am, edited 1 time in total.

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

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

Post by ptujec » Fri Sep 10, 2010 11:18 pm

no-username wrote: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.

There is a fix. Read more here:
http://github.com/kuroir/Launchbar-Twitter-Tools

beerich
Rank 4
Rank 4
Posts: 161
Joined: Thu Apr 05, 2007 11:05 am
Location: Toronto

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

Post by beerich » Thu Nov 04, 2010 10:02 pm

Hi folks.

Followed the directions, and nothing is happening...the script is running for about ten seconds, and it isn't posting. Any idea what I should be testing or looking for? This is a useful script. I'm using YoruFukurou (heh) at the same time. That shouldn't be a problem as they are mutually exclusive in posting, right?

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

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

Post by ptujec » Thu Nov 04, 2010 10:26 pm

beerich wrote:Hi folks.
Followed the directions, and nothing is happening...


The script stopped working due to a change of the authentication method Twitter is using. I updated the script a while ago and now decided to also update the directions. Hope that helps.
Last edited by ptujec on Mon Jan 03, 2011 11:53 pm, edited 2 times in total.

beerich
Rank 4
Rank 4
Posts: 161
Joined: Thu Apr 05, 2007 11:05 am
Location: Toronto

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

Post by beerich » Thu Nov 04, 2010 10:35 pm

I see. OK, thanks for the update.

aristidesfl
Rank 3
Rank 3
Posts: 120
Joined: Sat Feb 27, 2010 12:54 am

Re: How to use LaunchBar for Twitter

Post by aristidesfl » Thu Jan 13, 2011 8:19 am

took ptujec's script and added a few things:
- Keychain support
- Twitter icon on growl notifications (You need to have the free Twitter.app in your Applications forlder)
- goo.gl url shortening service

http://forums.obdev.at/viewtopic.php?f=24&t=5347

Post Reply