I am new to scripting and I found this script online that seems to do what I need after I tweaked it a bit. I am trying to close a popup window once it opened, once the popup window opened I need a flag to change from false to true, and vise versa the next time the window opens.
It seems like the place where I currently define the flag "connected" is a part of the loop and its being re-initialized every iteration, hence always true. I need to initialize it somehow only once and pass it inside the loop.
@if (@CodeSection == @Batch) @then
@echo off
set SendKeys=CScript //nologo //E:JScript "%~F0"
color 0a
:loop
%SendKeys% "{TAB}{TAB} "
timeout /t 60 /nobreak >nul
goto :loop
@end
var WshShell = WScript.CreateObject("WScript.Shell");
var connected = true;
if (WshShell.AppActivate("Popup window title")) {
if (connected) {
WScript.Echo("Inside Connected");
connected = false;
WshShell.SendKeys(WScript.Arguments(0));
}
else {
WScript.Echo("Inside Disconnected");
connected = true;
WshShell.SendKeys(WScript.Arguments(0));
};
}
I also tried using the set command right after the "set SendKeys" like this "set connected=true" and then I can use this variable like this %connected% within the scope but its not defined when I try to access it in the if statement.
Any help would be much appreciated!