could you not do something like this.

wherever you find the window open
Timer2.interval = 1000
Timer2.enabled=true
x = x + 1
if x = 5 then
'close the window
x = 0
timer2.enabled = false