set the focus to the window
window.focus(); // the window becomes the focus, if possible
if you want to continue with script in this window, you must set a macro command
let lw=window;
// go to other windows
lw.setfocus();
macro.sleep(0.1);
// now script is running in this window