« Skype Making an Appearance at CES | Main | Whom to Follow in the VoIP World »

Scripting Skype

Guest post by Vincent Oberle, Skype developer

Scripting simple tasks

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.

 

Moods to Twitter and command-line file transfer

I have blogged before about how using the Skype4Py library makes it very easy to script Skype and add little features to it, in a portable way. I have written two such little scripts recently. Their code is short and simple, and while I only tested them under Linux they should also work under Windows and Mac. They can be found with my Skype tools.

The first script will send your own mood messages to Twitter. There are two reasons for doing that. First many people use the mood message like Twitter, to say what they think or as a micro-blogging tool. So the mood message can be a very good “Twitter editor”. The second reason is that Skype doesn’t keep an history of your mood messages. This provides such an history, which can be private if you set your Twitter privacy settings accordingly.

The second script is to make my life easier. Under Linux I’m often in the command-line and I often have to send some file to colleagues. Currently that requires to get to the Skype UI, find the contact, choose the Send file option and navigate to the directory where my file to send is, lots of clicks.

So I’ve written the little send_file.py script. Just specify the Skype name(s) or the display name(s) of the people you want to send the file too, and it will open the file selection window to the current directory. From there you just have to choose the file to send. Why not specify directly the file name to transfer on the command-line? The Skype API doesn’t allow this, to prevent external applications to transfer files without the knowledge of the user. Yet despite this limitation, the script makes the file transfer operation much faster.

Note that “send_file.py John” will be enough to send the file to all contacts that have John in their name. Under Linux, this script requires at least Skype 2.0.0.27.

TrackBack

TrackBack URL for this entry:
http://skypejournal.com/blog-mt/mt-tb.fcgi/3832

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Brought to you by:

Convenos_125x125.active.gif

Auto generated tags