The Weblog of Vincent Oberle - Thoughts and opinions about technology and business

Scripting Skype

I’ve been using Python as my main scripting language for a while now. The Skype Linux tools I wrote a little while ago were already in Python. They used a custom wrapper for the API that Skype exposes for 3rd party applications. There is however a much better Python wrapper available now, Skype4Py, which is even officially supported by Skype.

With it, it becomes quite simple to script Skype for some simple tasks. Added benefit of using Python, your scripts will be portable across the 3 desktop platforms supported by Skype, Windows, Mac and Linux.

Here is an example of a small scripts I wrote to solve a problem.

Skype multi-chats are great for discussions on a project or in a team. But sometimes I need an answer from each member of a multi-chat. Just throwing the question in the chat will result that systematically some people don’t answer (don’t ask me why, I don’t get it either…). So I wrote a little script that will send as individual chat messages the text that follows the /all command. For example write in the multi-chat:
/all When do you go in holidays this summer?
and each member of the chat will receive the “When do you go in holidays this summer?” individual message.

Here is the code:

import Skype4Py
import re

skype = Skype4Py.Skype()
skype.Attach()  # Attach to Skype client

def message_status(Message, Status):
    if Status != Skype4Py.cmsSent: return
    if Message.Sender != skype.CurrentUser: return
    r = re.search (r'/all (.+)', Message.Body)
    if r:
        msg = r.group(1).strip()
        for member in Message.Chat.MemberObjects:
            if member.Handle == skype.CurrentUserHandle:
                continue # don't sent to myself
            skype.SendMessage(member.Handle, msg)

skype.OnMessageStatus = message_status

while(True): pass # Infinite loop, ctrl^C to break

Intercepting chat messages can be used for many things. Do you want a /sms command in a chat that will send an SMS to each member in the chat? It will probably not take you much more lines of code.

Leave a Reply