APPS = Array("Untitled - Notepad", "Calculator") 'window captions of the applications which should get rotated
Const INTERVAL = 5 'interval between rotations in seconds
MONITORS = Array() 'if apps should only be rotated between certain monitors, enter the monitor numbers here, for example Array(2,3)

Const FINDWND_TITLE = 1
Const MOVEMONITOR_NEXT = -1
Const WNDCHANGE_CLIP_TO_WORKSPACE = 2
Set wnd = CreateObject("UltraMon.Window")
Do While True
    WScript.Sleep INTERVAL * 1000
    
    For i = 0 To UBound(APPS)
        caption = APPS(i)
        If wnd.Find(caption, "", FINDWND_TITLE, 0, 0) = True Then
			If UBound(MONITORS) = -1 Then
				'rotate on all monitors
				wnd.Monitor = MOVEMONITOR_NEXT
			Else
				curMon = wnd.Monitor
				nextMon = 0
				For j = 0 To UBound(MONITORS)
					If MONITORS(j) = curMon Then
						If j = UBound(MONITORS) Then
							nextMon = MONITORS(0)
						Else
							nextMon = MONITORS(j + 1)
						End If
					End If
				Next
				
				If nextMon = 0 Then nextMon = MONITORS(0) 'app isn't on any of the defined monitors, move it to the first one
				
				wnd.Monitor = nextMon
			End If
			
            wnd.ApplyChanges WNDCHANGE_CLIP_TO_WORKSPACE
        End If
    Next
Loop
