Thanks a Lot for the solution. Its works like a charm.
However I wanted to put in a check if the system is locked or unlocked. If this script runs when the system is unlocked I see multiple windows so what do I need to check to know whether the system is locked ?
Thanks in advance.