Saturday, August 14, 2010

Posting Tweets via Command Line

After spending some time in the past week updating my Linux server and spending a lot of time in the command line, I wanted to take a look at methods to post to Twitter.  Since there are many parallels in the way you communicate to StatusNet, I decided to play with the options I found for twitter and modify them to post to StatusNet.

The most common method was using cURL, a free, cross-platform, command line utility that is already on most Unix based systems. Once installed you can post using this format:

'curl -u username:password -d status="Rockin' the tweet with cURL"'

Now that we know the setup you can type in your own "username" and "password" in the script and type your status between the "".  Rudimentary, but you get the idea.  I am no programmer, but I do enjoy taking snippets and adding automation to them, whether that be with an interface or patching piece together to get to the end result.
I like the simplicity of a little Mac app called Automator.  It is a way of graphically taking snippets or actions and daisy chaining them together to perform tasks.  I ties into many other applications on the Mac but also can be tied to scripts and other command line tools. 

I added a task to ask for text, which when the app runs it pops up a dialog and then passed it to a shell script task.  In the shell I used the "Pass input as arguments" and typed in my username and password into the cURL script I pasted in.  I replaced the actual post text between the "" with '$@', passing the entered text from the prompt into the script and running it.

I am going to play with a few other ways to automate this but I will leave it as a geek tool and leave the beautiful applications to be built by coders! ~Lou