I found out a way to make it work.
If i click on the window to select it, before i open the alert, it works, the only problem is that i manually have to double tap the header on the window to select it.
So how do i select the window through script so it's done automatically