Skip to main content.

Fanatic Attack is about entrancement, entertainment, and an enhancement of curiosity.

 

Twittering from OpenOffice.org

category: Open Source

by Dmitri Popov

Using extensions like TwitterFox and TwitBin , you can post messages to Twitter directly from within the Firefox browser. But what if you spend most of your time in OpenOffice.org and want to submit tweets without leaving the convenience of the office suite? A simple OpenOffice.org Basic macro can help you to solve this problem.


To send messages to Twitter from OpenOffice.org, you need cURL a cross-platform command-line tool for transferring files with URL syntax. It’s available for Linux and Windows, and you have to install it on your machine before you start writing the macro. cURL comes preinstalled on many popular Linux distributions, so if you are using Ubuntu or Mandriva, you don’t have to install anything. On Windows, you have to download the latest release of cURL, unzip the downloaded archive, and move the curl.exe executable into the WINDOWS\system32 directory.

Using cURL, you can “transfer” messages to Twitter by sending a command to the http://twitter.com/statuses/update.xml address, for example:

curl -u username:password -d status=”Twittering from OpenOffice.org” http://twitter.com/statuses/update.xml

To make cURL work with OpenOffice.org, you can use the Shell command, a powerful OpenOffice.org Basic tool that can launch virtually any external application and pass some data to it. For example, you can open a specified URL in the Firefox browser:

Shell (”firefox”, 1, “http://www.openoffice.org/”)

Using the Shell command and a couple of other tricks, you can create a macro that displays a simple input box where the user enters a Twitter message, and then passes it to cURL, which then takes care of the rest.

To display an input box you need to write just a single line of code:

InputText=InputBox(”Your message:”, “Post to Twitter”)

The text which the user types into the text field becomes a tweet which the macro sends to Twitter. But there is a tricky part: cURL can’t handle spaces between words, so they must be replaced by the %20 string. For example, the “My first tweet” message must be converted to “My%20first%20tweet.” OpenOffice.org Basic has the Split and Join routines that can help you to do just that:

SplitStr = Split(InputText, ” “)
Tweet = Join(SplitStr, “%20″)

The first statement chops the string into separate words, while the second statement glues them back together using %20 instead of spaces.

Next, the macro constructs a string that will be used as a cURL command:

TwMessage=” -u username:yourpassword -d status=” & “” & Tweet & “” & ” http://twitter.com/statuses/update.xml”

Don’t forget to replace the username:yourpassword part with your actual Twitter user name and password.

Finally, the Shell command launches the CURL tool and passes the created message string to it:

Shell(”curl.exe”, 1, TwMessage)

The code above works on Windows, and if you are using Linux, it should look like this:

Shell(”curl”, 1, TwMessage)

That’s all there is to it. Here is the full macro in all its glory:

Sub PostToTwitter()
InputText=InputBox(”Your message:”, “Post to Twitter”)
SplitStr = Split(InputText, ” “)
Tweet = Join(SplitStr, “%20″)
TwMessage=” -u username:yourpassword -d status=” & “” & TwitterStatus & “” & ”
http://twitter.com/statuses/update.xml”
Shell(”curl”, 1, TwMessage)
End Sub

This is a very basic macro that allows you to post messages to Twitter, and it can be improved in a number of ways. For example, you can modify the macro, so instead of entering text in a separate input box, the user can select a text fragment in the currently opened document and post it to Twitter. To do this, replace the InputText=InputBox(”Your message:”, “Post to Twitter”) statement with the following code:

TxtSnippet=ThisDoc.getCurrentController().getSelection().getByIndex(0).getString()
SplitStr = Split(TxtSnippet, “&”)
TwitterStatus = Join(SplitStr, “%20″)

Also, if you want the macro to work on Windows and Linux without modifying it, you can use the GetGUIType routine to use the correct Shell statement depending on the current platform:

If GetGUIType=1 Then
Shell(”curl.exe”, 1, TwMessage)
Else
Shell(”curl”, 1, TwMessage)
End If

Finally, for those who don’t feel like getting their hands dirty with OpenOffice.org Basic coding, here is the OOoTwitter extension based on the described macro. Once installed, it adds the Post To Twitter command to the Tools -> Add-Ons menu. To replace the username:password string in the macro with your actual Twitter user name and password, choose Tools -> Macros -> Organize Macros -> OpenOffice. org Basic. Select then the OOoTwitter -> OOoTwitter -> PostToTwitter macro, press OK locate the username:password string and replace it with your own user name and password. That’s it! Now you can twitter from OpenOffice.org.

Download the OOoTwitter Extention for Openoffice.org

by Dmitri Popov of Nothickmanuals.info

Posted by FA Editors at 12:54 PM PDT

comments

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>