Update Twitter from your desktop

Update your Twitter status directly from your computer desktop with this simple script. Download the script, modify it to match your Twitter account settings and off you go!

Post to Twitter from your desktop

This is a slightly modified version of the basic twitter script. This file is more or less the same, but this modified version is a sample which you could use in real world. You can drop this script somewhere on your computer. When you click it, it asks you to type the message.

Open notepad and copy 'n paste the code below into a new txt file. Then save it as "DesktopPostToTwitter.vbs" (or whatever filename you want). Change the 2 constants wich containing your login information into your own. Save it, and close it. Double click the script file and you will see the messagebox appearing asking for your input. Type in your message and it appears on your Twitter.

' Scriptname: DesktopPostToTwitter.vbs
' With this script you can update your Twitter status
' directly from your desktop
' July 2009 - Erick Hiemstra
' more info:
' http://sitejunction.awardspace.com/vbscript_tweets/desktop_script/

OPTION EXPLICIT 'Make sure to declare all your variables!

' ========================================
' In this block you enter your account
' settings.

Const conUsername = "Your account login" ' Your Twitter username
Const conPassword = "Twitter password" ' Your Twitter password

' ========================================
' This is where the actions are triggered

'Catch the user response in a variable
Dim strMessage
strMessage = InputBox("Your message: ","Update Twitter status","")

'Validate if the user has entered some text
' (.. sure you want some more validation here)
If strMessage = "" Then

     ' If nothing is entered, show a message
     MsgBox "Message cancelled...", vbOkOnly, "Update Twitter status - Cancelled"


     ' If there is some input from the user,
     ' then post it to twitter.     
     MsgBox SendToTwitter(strMessage)
End If

' ========================================
' after this block you can find the function
' doing all the work
Function SendToTwitter(strMessage)

     ' This is the function wicht does all the work.
     ' It uses XMLHTTP to post your message to Twitter..
     Dim objHTTP
     Set objHTTP = CreateObject("Microsoft.XMLHTTP")
          ' At these two lines the actual response is posted to
          ' Twitter
          objHTTP.open "POST", "http://twitter.com/statuses/update.xml", false, conUsername, conPassword
          objHTTP.send "status=" & strMessage
          ' The function stores the Twitter response to the result of
          ' this function, so we can display this later
          SendToTwitter = objHTTP.responseText
     Set objHTTP = nothing 'Release the object
End Function

You can also download the script as a text file here. Right click with you mouse on the download link, choose "save as" and change the *.txt extension into the extension *.vbs. To edit the file you can open it again with notepad.

In the next chapter I will show you a more user friendly way to present the script to your users by using this script in a HTA file. Do you have got problems with this script? You can send me an e-mail.