I have spent a little time trying to find out the best way to send an
SMS message to a cellphone using Linux. There is a smattering of
information scattered around, but I haven't found a complete explanation
in any one place and the documentation of the SMS interface in
kaddressbook seems to be a little lacking so I have attempted to
document something here in the hopes it may be useful to people
interested in the topic.

There seems to be two types of SMS messages. The "slow" type uses an
"email to SMS" gateway of the network provider (most free SMS web
messaging services use this method). Slow type SMS messages may not
always work if, for example, the network provider has not activated this
type of gateway, or the cellphone is on an MVNO ("mobile virtual network
operator" ie a cellular service provider like Virgin Mobile USA who
resells calling minutes from one or more real carriers). The "fast" type
uses another type of gateway for which a charge is normally incurred by
the sender of the message. Skype uses the fast type SMS messaging and
charges a fee for each message sent (Eur 0.09/message within North
America for example). In the current Windows version Skype has the
ability to send an SMS message directly but in the Linux version of
Skype the SMS service is not available in the Skype program itself.
However, there is a Skype API which can access these features of Skype.
Skype4Py is a Python wrapper for the Skype API and can be found here:

https://developer.skype.com/wiki/Skype4Py

In addition, there is a set of Python command line tools which use
Skype4Py called "Skype Tools 0.11". Skype Tools 0.11 can be found here:

'Vincent Oberle Command-line tools for Skype'
(http://www.oberle.org/skype_linux_tools/)

The particular tool we are interested in is the Python script
send_sms.py. After installing Python, Skype4Py and Skype Tools, and with
Skype for Linux running in the background you will be in a position to
send an SMS message from the command line using send_sms.py. The first
time you try to use send_sms.py you will need to give permission to
Skype to allow Skype4Py and "sms_sender" (the "friendly name" of
send_sms.py) to access Skype. Check under:

S -> Options -> Public API -> Allowed Programs

I am indebted to 'Happy coding Blog Archive How to send SMS in
Linux using Skype' (http://blogs.igalia.com/eocanha/?p=77) for
documenting the first two pieces of the Linux to SMS puzzle for me.

The final step is to integrate send_sms.py into the SMS message feature
of kontact/kaddressbook. For the telephone number of the cellphone,
under "Mobile" enter the telephone address in the form required by
Skype. For example if the telephone number is 123-456-7890 enter
+11234567890 as the "Mobile" number. The "Mobile" tag shows "(SMS)" at
the end of the telephone number, as in:

Mobile: +11234567890 (SMS)

Clicking on "(SMS)" (do not click on the telephone number) throws up a
small dialog window with the title "Send SMS - Kontact" in which the
text message can be entered and also shows the character count of the
message being prepared. For the purpose of the script below, if a
newline is required in the message enter "\\n" as in: "This is line
1\\nThis is line 2" Do not enter control characters such as newlines
directly and just let the message string wrap inside the dialog box.

After entering the text message in the dialog press the "Send" button
and the message will be sent. Skype must be running in the background of
course.

Steps to prepare kaddressbook for message sending:

Pressing the "Send" button in the "Send SMS - Kontact" window creates a
small text file containing the text with the filename
\tmp\kde-[username]\kontact[6 char string].tmp (in KDE3). The variable
"%F" created by kaddressbook contains this file name. The variable "%N"
contains the telephone number string. So we have the information
required for an SMS message but the text is in a file instead of the
last part of the input string as required by send_sms.py. The bash
script below which I have called "sendSMS.sh" will prepare and send the
correct input string to send_sms.py. Prepare kaddressbook to use
sendSMS.sh by making sendSMS.sh executable and placing it somewhere in
your $PATH such as /home/[username]/bin/. Finally, set up a kaddressbook
script hook as follows:

Kontact -> Settings -> Configure Address Book... ->
Script-Hooks -> SMS Text:
enter the following: sendSMS.sh %N %F

Here is my bash script sendSMS.sh:

#!/bin/bash
# prepare string for execution by send_sms.py
# ***SKYPE FOR LINUX MUST BE RUNNING***
# $1 is %N = telephone number in form required by Skype
# $2 is %F = file name containing text of message
# this is automatically created by kaddressbook
# after closing the SMS message window
# actual file is named (in KDE3)
# /tmp/kde-[username]/kontact[6 char string].tmp
# Text must be a single line string as the script
# as written only captures the first line of text.
# Line breaks in text message may be embedded with \\n
# eg. This is line 1.\\nThis is line 2.
# enter into Kontact->Settings->
# Configure Address Book...->
# Script-Hooks->SMS Text: sendSMS.sh %N %F
exec 6<&0
exec < $2
read line1
string=$1" "$line1
exec 0<&6 6<&-
send_sms.py $string

A more elegant way to do this would be to simply modify the python
script send_sms.py to use the file name and use the revised Python
script as our kaddressbook hook, but as I am unfamiliar with Python
programming I devised the little bash script. The script just redirects
the contents of the first line of the file containing the SMS message
into the bash variable "line1" and concatenates into "string" the
variable with a prepended telephone number and space which is then used
as the input to send_sms.py which together with Skype4Py access the
Skype API and send the SMS.


--
apm04
------------------------------------------------------------------------
apm04's Profile: http://forums.opensuse.org/member.php?userid=1948
View this thread: http://forums.opensuse.org/showthread.php?t=401304