November 25, 2008

call (4)for tea .ruby script (rb)

Filed under: Uncategorized — Tags: , — yasi8h @ 3:28 pm

this is a tiny ruby script that i wrote some time back. it does a very simple(but helpful, at least for me :)) task, that is it will send a given message to a pre configured list of gmail(actually anything that do jabber) accounts. and after this it will wait and listen for any incoming messages, if it receives any it will print them to the screen. usually when i am at work and its time for tea, i IM all my friends and ask them whether they want to go for tea. so to do this the ‘manual’ way is tiring… specially when you are doing twice a day, 5 times a week! hence the script. it was a piece of cake to write this with ruby + xmpp4r-simple. wow these gems are ‘totally cool’ 🙂

note that you will have to edit the script to reflect your account info, the first time your are running this.

#need xmpp4r-simple : gem install xmpp4r-simple
#usage: call4tea message(s)

require ‘rubygems’
require ‘xmpp4r-simple’

#edit these settings to make it work for you
ACCOUNT = ‘” href=”>xxxxxx@gmail.coma>’ #the account used by the script to send/receive messages
PASSWORD = ‘password’ #password for the above account
FRIENDS = [“” href=”>yyyyyyy@gmail.coma>”, “” href=”>qqqqqqq@gmail.coma>”, “” href=”>ssssssss@gmail.coma>”] #array of friend’s accounts to whome you want to send the message(s) to

puts “call4tea”

#do some validation
if ACCOUNT.empty?
puts “you should specify a valid account to be used with the messaging in the script”

if PASSWORD.empty?
puts “you should specify a valid password to be used with the messaging in the script”

if FRIENDS.size < 1 puts "you should specify the FRIENDS array with accounts of your friends, it cannot be empty" Process.exit end if ARGV.size < 1 puts "no messages specified, exiting" Process.exit end jabber =, PASSWORD) FRIENDS.each do|friend| ARGV.each do|message| jabber.deliver(friend, message) end end puts "sent #{ARGV.size} message(s) to #{FRIENDS.size} friend(s)" #lets wait and print any responses we receive to the screen while true jabber.received_messages do |msg| puts "#{msg.body}" if msg.type == :chat end end [/sourcecode]


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at

%d bloggers like this: