Page 2 of 3

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

Posted: Fri Apr 10, 2009 2:22 pm
by ptujec
-- this reply contained outdated information so I deleted it --

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

Posted: Wed Oct 14, 2009 6:39 pm
by sjk
Try Twitter Support :: Frequently Asked Questions; this forum isn't a general help/support resource for Twitter.

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

Posted: Sun Feb 07, 2010 7:59 pm
by donovanwatts
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.

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

Posted: Sun Feb 28, 2010 5:16 pm
by asathomas
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

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

Posted: Sun Feb 28, 2010 6:45 pm
by ptujec
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

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

Posted: Tue Mar 02, 2010 4:33 am
by aristidesfl
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)

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

Posted: Fri Mar 05, 2010 7:31 pm
by aristidesfl
this is applescript fot the macs

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

Posted: Thu Apr 29, 2010 12:46 pm
by ptujec
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;
}

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

Posted: Fri Aug 06, 2010 8:23 am
by ptujec
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.

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

Posted: Thu Sep 02, 2010 5:04 pm
by ptujec
-- this reply contained outdated information so I deleted it --

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

Posted: Fri Sep 10, 2010 11:18 pm
by ptujec
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

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

Posted: Thu Nov 04, 2010 10:02 pm
by beerich
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?

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

Posted: Thu Nov 04, 2010 10:26 pm
by ptujec
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.

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

Posted: Thu Nov 04, 2010 10:35 pm
by beerich
I see. OK, thanks for the update.

Re: How to use LaunchBar for Twitter

Posted: Thu Jan 13, 2011 8:19 am
by aristidesfl
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