Tuesday, March 17, 2009

The Ari sleeps tonight

Do you use Skype? Me too, but for a long while I refrained from using it because it allows people to call you at any time they want, unless you remember to set it to Do Not Disturb or offline when you go to sleep. As most of my friends and family are in Israel, which is 10 hours ahead, this was even more troublesome. So what can YOU do?

Well, fortunately, Skype has an API – a “Application Programming Interface”, which allows anyone to write a program that will communicate with Skype directly. Many applications have APIs, which are up to the application developers to create. Microsoft, for example, has APIs for almost all of its software.

Skype’s API is not very well documented, so using theirs is not that simple, but I’m here to help. One can use that API using any programming language, but since not everyone has the tools to write and compile programs, I’ll use the built-in scripting engine of Windows to do it. This allows you to easily create the program with no prior knowledge or installation of complicated compilers.

To use this, all you have to do is open Windows’ NOTEPAD program, and copy-paste the following code into it. Then, save the file somewhere on your hard drive and give it the extension VBS. Next, edit the time-table set in the 1st two lines to select when Skype will be online and “Do Not Disturb”. Then, just use the windows scheduler to run this script once every hour. Whenever it runs, it will check the current day and time to determine if this is a weekend or not (assuming you stay up later on a weekend) and if Skype should be set to DND or online, and do it.

Note: The current settings set Skype to be DND from midnight to 9am on a weekday and from 1am to 11am on a weekend. The weekend days are set to Friday and Saturday since most people, I guess, go to sleep late on Fridays and Saturdays because they don’t have to wake up early on a Saturday and Sunday.

Code starts here:

TimeRangesOfflineWeekend = "1,2,3,4,5,6,7,8,9,10"
TimeRangesOfflineWeekday = "0,1,2,3,4,5,6,7,8"
Set oSkype = CreateObject("Skype4COM.Skype")
CurrentStatus = oSkype.CurrentUser.OnlineStatus
DND = 4
Online = 1
CurrentHour = int(timer/60/60)
Dayofweek = weekday(date)
if Dayofweek = 6 or Dayofweek = 7 then 'This is a weekend
if instr(TimeRangesOfflineWeekend,CurrentHour) then
SetSkype = 4 'Going to DND mode
SetSkype = 1 'Going ONLINE
end if
else 'This is NOT a weekend
if instr(TimeRangesOfflineWeekday,CurrentHour) then
SetSkype = 4 'Going to DND mode
SetSkype = 1 'Going ONLINE
end if
end if
Set oSkype = nothing

No comments:

Post a Comment