Outlook to Skype SMS

March 11th, 2010

I wanted to know when a process on a customer’s server had failed. In fact I wanted it to wake me up in the middle of the night so that I could fix it.

About the only usable outbound communication supported by the server is email, but my phone is not email capable (well it is, but not for work emails!).

So a colleague mentioned using MSN chat or Skype chat to send comments, and that set me wondering…

Skype has a COM library which can be used to interface with the Skype application. (A reinstall of Skype with the Extras Manager option ticked was needed to get the library installed.) The Skype4COM library allows you to send SMS. Outlook of course allows you to apply rules to incoming mail messages, and one of these allows you to run some code in a VBA module (the run a script option).

So to put it all together:

  1. A script on the customer’s server will monitor another script’s progress. If it detects a particular condition it will generate an email sent to my work email account.
  2. Outlook has a rule to look for specific text in the email subject (for example “ERROR”).  If it detects a suitable email, it will run a piece of VBA.
  3. The VBA will call skype and send the SMS message

Installation of outlook VBA code

  1. Add the code below to an outlook module
  2. Change the phone number to be your phone number (A future feature might be to include the phone number in the email subject and set this dynamically)
  3. Add a reference to the Skype4COM object in the module.

Running the solution

  1. Have outlook open, running and make sure that macros are enabeld.
  2. Have Skype open and logged in. (and have some credit for sending sms!) (it is possible to launch skype from the VBA script but I’m still tinkering with this to get it working reliably)
  3. Wait for email’s to arrive.

The Code

Sub SendSMSRule(Item As Outlook.MailItem)
    Dim strContact As String

    strContact = "+441234567890" 'Your phone number

    subSendSMS strContact, Item.Subject

End Sub

Private Sub subSendSMS(strRecipients As String, strMessage As String)
    Dim objSkype        As SKYPE4COMLib.Skype
    Dim objSMS          As SKYPE4COMLib.SmsMessage

    Set objSkype = New SKYPE4COMLib.Skype
    objSkype.Attach , True

    Set objSMS = objSkype.CreateSms(smsMessageTypeOutgoing, strRecipients)
    With objSMS
        .Body = strMessage
        .Send
    End With
KillObjects:
    Set objSMS = Nothing
    Set objSkype = Nothing
End Sub

Library offers fee tea bag

February 27th, 2010

No really.

I went to collect a book I had reserved at my local Wolverhampton Library, and as I had the item issued, I was offered a free tea bag.

Bemused; politely; I said no, thank you, I don’t drink tea.

P.S. Wolverhampton Libraries, why can’t I reserve a book on-line if it is NOT on loan? quite often I would prefer you to send the book to my local library if it is in the Central Library on the shelf. And I know your system could do it!

A little bash deployment assistant

February 6th, 2010

I wanted to copy some files from one directory to another while I am working on my wordpress blog-in-blog plugin.  Basically I needed to copy the files checked out from svn, from the working directory, to the root of the web directory on my local machine.

Feature requirements:

  • Should only move a file if it has been edited. (we assume that the filesize will have changed by at least 1 byte!)
  • Should not just sit there copying all the time.
  • Should find out about all files in the specified directory.
  • Should report when it updated the file and which file was updated
  • First run should copy all files to the destination directory. (assumes I have updated my working copy from svn)

So after several attempts, here is a more polished version which stores the filename and the last size of the file in a ‘bash hash’. OK bash doesn’t have hashes (mores the pity) but reading around on the web I found this post with a comment from Scott Mcdermott which does the job nicely (once I had stripped offending characters from the file names).

So here is the full code of the deployment assistant:

#!/bin/bash
# script to deploy code from SOURCEDIR to DELIVERDIR 

PROJECTNAME="blog-in-blog"
SOURCEDIR=blog-in-blog/trunk
DELIVERDIR=/var/www/wordpress/wp-content/plugins/blog-in-blog/
FILENAMES=blog-in-blog/trunk/*
LASTFILESIZE=0
COUNTER=1

echo "======================================================"
echo -e "delivering changes \n\tin \033[1m$SOURCEDIR\033[0m \n\tto \033[1m$DELIVERDIR\033[0m"
echo "======================================================"		

if [ -z $1 ]
then
	echo "usage$  $0 "
	exit 1
fi

hash_insert ()
{
	local name=$1 key=$2 val=$3
	eval __hash_${name}_${key}=$val
}

hash_find ()
{
	local name=$1 key=$2
	local var=__hash_${name}_${key}
	echo -n ${!var}
}

while true
do
	for FILE in $FILENAMES
	do
		FILESIZE=$(stat -c%s "$FILE")

		#tidy up file to avoid problems in variable name
		FILE=`basename $FILE`
		FILEORIG=$FILE
		FILE=`echo "$FILE" | sed 's/[\.\_-]//g'`

		LASTFILESIZE=`hash_find fileHash $FILE`
		#echo "filesize:"$FILESIZE
		#echo "lastfilesize:"$LASTFILESIZE
		if [ "$FILESIZE" != "$LASTFILESIZE" ]
		then
			echo "--- $COUNTER ---------------------------------------"
			date
			echo -e "deploying \033[1m$FILEORIG\033[0m from project $PROJECTNAME"
			echo "Size was $LASTFILESIZE bytes, now $FILESIZE bytes."
			cp $SOURCEDIR/$FILEORIG $DELIVERDIR
			hash_insert fileHash $FILE $FILESIZE
			UPDATE=1
		elif [ "$UPDATE" -ne "1" ]
		then
			UPDATE=0
		fi
	done

	if [ "$UPDATE" = 1 ]
	then
		echo "======================================================"
		let COUNTER+=1
		UPDATE=0
	fi

	sleep $1
done
#ends