Skype4py Script for Sending Skype Messages from the Linux Ubuntu Console
A short note on how to make Bash scripts send messages to Skype.
First you need to download the Skype4py library.
Unpack it, go into the folder and run setup.py:
sudo python setup.py
Next we need to create the script we’ll send messages with. It’d be good to put it in a folder that’s part of the $PATH environment variable - that lets you call the script from any directory in the system without the full path to it.
You can check $PATH like this:
echo $PATH
Here’s what I got:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/java/jre1.7.0_15/bin
It’s best to do this under the user account the script is meant to run as.
Take the first folder that comes to hand (/usr/local/sbin) and create the file send_message.py in it:
#!/usr/bin/python
#
# This script allows to sent messages to skype
# using skype API for python
import Skype4Py
import sys
client = Skype4Py.Skype()
client.Attach()
user = sys.argv[1]
message = sys.argv[2]
client.SendMessage(user, message)
The problem with this scheme is that Skype4Py works with a running instance of the Skype application on the system and pulls its info from that. Connecting is done by the plain client.Attach function. If several Skype applications are running on the system, client.Attach will connect to whichever one was launched last.
Usage:
./send_message.py contact_user.Handle "message"
Getting the name you're logged into Skype under (can be used to figure out which Skype application Skype4Py is working with):
python -c 'import Skype4Py; client = Skype4Py.Skype(); client.Attach(); print client.CurrentUser.FullName, "(", client.CurrentUser.Handle, ")"'
Showing the contacts list:
python -c 'import Skype4Py; client = Skype4Py.Skype(); client.Attach();
for user in client.Friends: print user.Handle, "(", user.FullName, ")";'