Return to previous window if no activity for period of time

I know i got to use something like below, but I dont know where to put it in event handler:

if system.util.getInactivitySeconds() > 100 and system.nav.getCurrentWindow() != “TEST1/My Window1”:
system.nav.swapWindow(currentWindow, ‘TEST1/My Window1’).

Thanks in advance

You would want to put this on a client timer script.