I’m guessing the problem is that you expect the above code to act whenever the active/inactive status of Chrome changes. There is nothing that you’ve shown that routes the script’s execution to that code so that it would be acted on more than the one time the script is initially run. You would need to have it executed regularly either by using
SetTimer,
Loop, or by using something like
OnWin() where you would register the change in active status as an event to trigger this code. Otherwise, there is nothing in your script that would have the checks being done continuously (or at all for that matter, other than once when the script is run).
By the way, you are missing braces around your second
If’s block of code. Also, rather than an
If with the opposite condition, you should just use
else. That’s what it’s for.