ThomThom's Website

MSN scripting in DesktopX with events

26 Aug 07 - 13:00

While I was looking through the Yahoo! Widget manual I came across an interesting piece of code snippet demonstrating how to connect to COM objects. The code snippet showed how to connect to MSN and access methods and events.

I tried the script in DesktopX with some adaptation and managed to get access to the methods. However, there was no way of handling the events from COM objects in DesktopX.

While I was doing this I was rambling about it on #stardock. And fortunately for me, Julien was there. He had the idea of using a Script Component.

The script component was able to connect to the MSN COM object and receive the events. Now I could connect to the script component and make it act as a proxy to the MSN object and receive the events.

I build a little DesktopX package that demonstrate how to interact with the MSN automation object.

Connect to MSN object

To begin a MSN project you need to add the file MSN.wsc as a custom file to one of your objects. Then you can refer to it via the script as such:


var MSN;
MSN = GetObject('script:' + Object.Directory + 'MSN.wsc');

Dim MSN
Set MSN = GetObject("script:" & Object.Directory & "MSN.wsc")

The DesktopX package example I made demonstrate how to get a list the contacts in your contact list in VBScript and JScript.

Events

In order to receive events from the MSN objects you need to register the functions you can't to be executed whenever an event is triggered.


var MSN;
MSN = GetObject('script:' + Object.Directory + 'MSN.wsc');
MSN.OnContactStatusChange = hello_world;

function hello_world(contact, status)
{
  // contact is the contact that changed status
  // status is the new status code of the contact
  Script.MsgBox(contact.FriendlyName);
}

Dim MSN
Set MSN = GetObject("script:" & Object.Directory & "MSN.wsc")
Set MSN.OnContactStatusChange = GetRef("hello_world")

Function hello_world(contact, status)
  ' contact is the contact that changed status
  ' status is the new status code of the contact
  Script.MsgBox(contact.FriendlyName)
End Function

This is a list of the events you can use:

  • OnAppShutdown
  • OnContactAddedToGroup
  • OnContactBlockChange
  • OnContactFriendlyNameChange
  • OnContactListAdd
  • OnContactListRemove
  • OnContactPagerChange
  • OnContactPhoneChange
  • OnContactRemovedFromGroup
  • OnContactStatusChange
  • OnGroupAdded
  • OnGroupNameChanged
  • OnGroupRemoved
  • OnIMWindowContactAdded
  • OnIMWindowContactRemoved
  • OnIMWindowCreated
  • OnIMWindowDestroyed
  • OnMyPropertyChange
  • OnMyStatusChange
  • OnSignin
  • OnSignout
  • OnUnreadEmailChange

Methods

At the moment, the only way to get access to the events and methods is by using the getMSNObject function. This means you'll have two objects related to MSN. I plan to make a new release which merges the two into one object. Check this page for updates.


var MSN, MSNobj;
MSN = GetObject('script:' + Object.Directory + 'MSN.wsc'); // Events
Set MSNobj = MSN.getMSNObject(); // Access to methods via MSNobj

Dim MSN, MSNobj
Set MSN = GetObject("script:" & Object.Directory & "MSN.wsc") ' Events
Set MSNobj = MSN.getMSNObject() ' Access to methods via MSNobj

Bring on the gadgets!

I hope that this will allow people to start making gadgets interacting with MSN. It could be simple contact lists residing on the desktop. Or even on the Vista Sidebar now that DesktopX 3.5 allows you to export to Sidebar gadgets. You could incorporate MSN into an address book. Or make a gadget where each user floats in your desktop like icons, displaying their status.

Comments

  • On 04.08.08 11:35 GMT Vinny said:

    hi, i have a music website called metalhedz(not online yet), and was wondering if i could change the personal message in msn messenger of the song name and the band name...
  • On 11.08.08 20:19 GMT Thomas Thomassen said:

    I'm not sure what you're trying to do. Are you trying to connect the MSN status with some part of your website via scripting?
Comments are closed due to spam. Thank you spammers, well done!