Distinguish one popup from another

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
thegame2010
Posts: 29
Joined: 04 Feb 2016, 18:14
Location: 'Murica

Distinguish one popup from another

Post by thegame2010 » 16 Feb 2016, 17:57

Attached I have screenshots of a popup in a couple browsers that pop up every 20 minutes or so at my work. I also have the Window Spy info for each.

What I would like to do is have it so as soon as this window (and not any other popup, which is the hard part) shows up, I send {Tab}{Enter} so that I actually click OK and remain logged in to that program.

I have been testing this with a msgbox. I have

Code: Select all

#8::Msgbox This is a popup!
running at the same time as

Code: Select all

Loop
{
	WinWait, ahk_class #32770
		Send {Tab}{Enter}
}
return
This works, but it doesn't distinguish my popup from the delete verification popup in Windows when you try to delete an item. "Are you sure you want to delete...."

This is a problem, since many things that I work on pop up in my browser. I have to find a way to distinguish these popups from other popups. Any suggestions? I don't know the syntax to make this kind of pseudocode work:

Code: Select all

Loop
{
	WinWait, ahk_class #32770
		If title = Timeout Warning...
			Send {Tab}{Enter}
		Else
			return
}
return
Attachments
Window Spy.png
SifJar
Posts: 398
Joined: 11 Jan 2016, 17:52

Re: Distinguish one popup from another

Post by SifJar » 16 Feb 2016, 18:10

Code: Select all

Loop
{
	WinWait, Timeout Warning
		Send {Tab}{Enter}
}
return
No need to complicate things with an if statement, WinWait can use title text to identify a window!
User avatar
thegame2010
Posts: 29
Joined: 04 Feb 2016, 18:14
Location: 'Murica

Re: Distinguish one popup from another

Post by thegame2010 » 17 Feb 2016, 15:56

None of the following loops work for these popups. I don't know where the hangup is. Perhaps I should add something that ensures that the popup is the active window prior to sending the keystrokes?

Code: Select all

Loop
{
	WinWait, Timeout Warning.
		Send {Tab}{Enter}
}
return
Loop
{
	WinWait, Timeout Warning
		Send {Tab}{Enter}
}
return
Loop
{
	WinWait, Timeout Warning. Click OK to not end the session. - Internet Explorer
		Send {Tab}{Enter}
}
return
iPhilip
Posts: 835
Joined: 02 Oct 2013, 12:21

Re: Distinguish one popup from another

Post by iPhilip » 17 Feb 2016, 16:44

Hi. The code below is untested but I would recommend the WinActivate command to make sure that the popup window gets the Send command. Given the information from Window Spy, it doesn't make sense to add any additional information to the window title. The window class is not the same between the two cases you showed in your original post.

Code: Select all

Loop
{
   WinWait, Timeout Warning
   WinActivate
   Send {Tab}{Enter}
}
return
Let me know if this helps.
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)
User avatar
thegame2010
Posts: 29
Joined: 04 Feb 2016, 18:14
Location: 'Murica

Re: Distinguish one popup from another

Post by thegame2010 » 19 Feb 2016, 09:14

None of the following seem to run ever. I tried with just a part of the title, and with the full title. I con't tell what's wrong here.

Code: Select all

Loop
{
	WinWait, Timeout Warning
		WinActivate
		sleep 100
   		Send {Tab}{Enter}
}
return

Loop
{
	WinWait, Timeout Warning. Click OK to not end the session. - Internet Explorer
		Msgbox I tried on IE
}
return

Loop
{
	WinWait, Timeout Warning. Click OK to not end the session. - Google Chrome
		Msgbox I tried on Chrome
}
return
User avatar
rommmcek
Posts: 1480
Joined: 15 Aug 2014, 15:18

Re: Distinguish one popup from another

Post by rommmcek » 19 Feb 2016, 10:18

Did you try to run the script as admin?
wizardzedd
Posts: 319
Joined: 23 Jan 2016, 23:03

Re: Distinguish one popup from another

Post by wizardzedd » 19 Feb 2016, 14:24

You may want to try
SetTitleMatchMode 2 to enable partial matching.
DetectHiddenWindows on
Other than that, I've also seen a thread where the popup title contains invisible characters, in which case the solution seems to be your initial approach.

Code: Select all

Loop
{
	WinWait, ahk_class #32770
	WinGetTitle, Title,
	IfInString, Title, Timeout Warning 
	{
		WinActivate, 	; May or may not be necessary
		Send {Tab}{Enter}
	}
	Else
		return
}

Hope it helps, best of luck!
User avatar
thegame2010
Posts: 29
Joined: 04 Feb 2016, 18:14
Location: 'Murica

Re: Distinguish one popup from another

Post by thegame2010 » 19 Feb 2016, 17:57

I am a domain admin, but I haven't yet Right-Clicked and run as admin explicitly.

I'll try SetTitleMatchMode. I hope to reply tomorrow with more results. Thanks, all!
User avatar
thegame2010
Posts: 29
Joined: 04 Feb 2016, 18:14
Location: 'Murica

Re: Distinguish one popup from another

Post by thegame2010 » 26 Feb 2016, 13:10

So I tried

Code: Select all

Loop
{
	WinWait, ahk_class Chrome_WidgetWin_1
	WinGetTitle, Title,
	IfInString, Title, Timeout Warning 
	{
		WinActivate, 	; May or may not be necessary
		Send {Tab}{Enter}
	}
	Else
	{
		return
	}
return
}

Loop
{
	WinWait, ahk_class IEFrame
	WinGetTitle, Title,
	IfInString, Title, Timeout Warning 
	{
		WinActivate, 	; May or may not be necessary
		Send {Tab}{Enter}
	}
	Else
	{
		return
	}
return
}
It didn't work. In fact, it only runs for about .2 seconds then closes. So I tried adding

Code: Select all

$p::Send p
to get it to continuously run. It stayed running. It did not detect the window though. I waited for the popup and then reloaded the script, hoping in that .2 seconds it would do its job. It didn't.

It's a real shame: undoing these popups in this way would make me a hero around the office.
wizardzedd
Posts: 319
Joined: 23 Jan 2016, 23:03

Re: Distinguish one popup from another

Post by wizardzedd » 26 Feb 2016, 13:25

you can put #persistant at the top to keep a script from closing. As far as the problem goes, I would recommend doing a little debugging to see where its failing.

Code: Select all

#persistent
Loop
{
	WinWait, ahk_class #32770
	WinGetTitle, Title, ahk_class #32770
	MsgBox % "Window detected, title is " Title
	IfInString, Title, Timeout Warning 
	{
		MsgBox The window is timout warning`, attemting to Close
		WinActivate, ahk_class #32770
		Send {Tab}{Enter}
	}
       sleep, 1000
}
Where does it break? Does it detect the window at all?
User avatar
thegame2010
Posts: 29
Joined: 04 Feb 2016, 18:14
Location: 'Murica

Re: Distinguish one popup from another

Post by thegame2010 » 26 Feb 2016, 13:57

Though I censored anything that I could think of as being identifiable, I think this might be useful to this situation. This is the popup itself:

Code: Select all

<html dir='ltr' lang="en"><head><title>Timeout Warning. Click OK to not end the session.</title>
<link rel="stylesheet" href="/cs/censored/cache/PSSTYLEDEF_SWAN_5.css" type="text/css">
 <script language='JavaScript'>document.domain = "CENSORED.com";</script>
</script>
<script language='javascript' type='text/javascript' src='/cs/censored/cache/PT_SAVEWARNINGSCRIPT_MIN_1.js'></script>
</head>
<body link="#0000CC" vlink="#FF0000" alink="#CECECE"  onload="window.setTimeout('this.close()', 118000);">
<table border='0' cellpadding='0' cellspacing='0' width='300' class='PSTEXT'>
<tr><td width='100%' align='left'>
<img src="/cs/censored/cache/NEW_PS_LOGO_1.gif" border='0' alt='' />
</td></tr><tr><td><br />
Your session is about to be timed out. As a security precaution, sessions end after 20 minutes of inactivity. Click OK to continue your current session.</td></tr><tr><td align='center'><br /><br />
<a href="javascript:window.opener.setupTimeout2();self.location='https://censored.CENSORED.com/censored/?cmd=resettimeout';this.close();">
<img border='0' src="/cs/censored/cache/PT_OK_1.gif" alt="OK" title="OK" /></a>     
</td></tr></table>
</body>
</html>
As you may have guessed, it isn't actually CENSORED.com. :lolno:
User avatar
thegame2010
Posts: 29
Joined: 04 Feb 2016, 18:14
Location: 'Murica

Re: Distinguish one popup from another

Post by thegame2010 » 26 Feb 2016, 14:08

Good news!!

The first part of my script works!

If in Chrome, the following script will press OK on the page:

Code: Select all

Loop
{
	WinWait, ahk_class Chrome_WidgetWin_1
	WinGetTitle, Title,
	IfInString, Title, Timeout Warning 
	{
		WinActivate, 	; May or may not be necessary
		Send {Tab}{Enter}
	}
	Else
	{
		return
	}
return
}
I am confused about why it doesn't work in IE:

Code: Select all

Loop
{
	WinWait, ahk_class IEFrame
	WinGetTitle, Title,
	IfInString, Title, Timeout Warning 
	{
		WinActivate, 	; May or may not be necessary
		Send {Tab}{Enter}
	}
	Else
	{
		return
	}
return
}
wizardzedd
Posts: 319
Joined: 23 Jan 2016, 23:03

Re: Distinguish one popup from another

Post by wizardzedd » 26 Feb 2016, 14:20

Have you tried this yet?

Code: Select all

#persistent
SetTitleMatchMode, 2
Loop 
{
	WinWait, Timeout Warning
	WinActivate
	Send {Tab}{Enter}
	sleep, 1000
}
User avatar
thegame2010
Posts: 29
Joined: 04 Feb 2016, 18:14
Location: 'Murica

Re: Distinguish one popup from another

Post by thegame2010 » 26 Feb 2016, 14:26

I am trying now. I also notice that even my previously posted success is limited: It only works right away. Even though it is persistent, it only actually does anything at the beginning. For testing purposes I threw a message box in the script too. This way I can tell if it detects the window and just doesn't close it.

I'll report back with results very soon, I hope. I feel good about this.

Code: Select all

#persistent
SetTitleMatchMode, 2
Loop 
{
	WinWait, Timeout Warning
	WinActivate
	Send {Tab}{Enter}
	sleep, 1000
	Msgbox It worked
}
User avatar
thegame2010
Posts: 29
Joined: 04 Feb 2016, 18:14
Location: 'Murica

Re: Distinguish one popup from another

Post by thegame2010 » 26 Feb 2016, 14:44

IT WORKS!!!!!!!!!!!!!

It doesn't seem to matter if it's Chrome nor IE. I'll even test it in Opera and Firefox just to see.

Thank you so much!
Post Reply

Return to “Ask for Help (v1)”