 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Ender13 Guest
|
Posted: Wed Jul 19, 2006 4:11 pm Post subject: Closing Idle Browser Windows |
|
|
Here is my situation, I am wanting to write a script that will close a browser window after a time if it is behind another program. I also want this script to run continuiously. here is what I have:
Loop
{
SetTitleMatchMode, 2
IFWinNotActive, Internet Explorer
{
Sleep 10000
WinClose, Internet Explorer
}
}
What is happening is this. When I open IE, it will stay open from anywhere between 3 and 10 seconds and close. Even if it is on top. It doesn't seem to stay open for any specific amount of time.
Am I just not understanding the IfWinNotActive application or the definition of Active correctly?
Why is the sleep command not holding for 10 seconds?
Any help would be grately appreciated.
Thanks in Advance,
Roy |
|
| Back to top |
|
 |
not-logged-in-daonlyfreez Guest
|
Posted: Wed Jul 19, 2006 9:56 pm Post subject: |
|
|
| Quote: | | I am wanting to write a script that will close a browser window after a time if it is behind another program. I also want this script to run continuiously. |
So, you need to check regularly (timer) if the browser window is not active (ifwinnotactive).
Create a timer that checks every, dunno, second, if your target window (be specific) is inactive.
If it is, stop the timer, start a sleep, close the window afterwards and start the timer again (if you need to, dunno if that window shows up again). If it's not, do nothing (return)... it will start the check again the next time it's triggered...
(no loop, timer...)  |
|
| Back to top |
|
 |
ParanoidX
Joined: 16 Dec 2005 Posts: 149 Location: Australia
|
Posted: Sun Jul 23, 2006 6:45 am Post subject: |
|
|
| Ender13 wrote: | | Here is my situation, I am wanting to write a script that will close a browser window after a time if it is behind another program. I also want this script to run continuiously | Basically, the prob with your script is | Code: | | WinClose, Internet Explorer | as this does not differentiate between whether it is active or not. It simply close the first occurence of IE, so the active one first and work its way down until all IE is closed.
When you: | Code: | | IFWinNotActive, Internet Explorer | It simply translate to, do whatever, when IE is not active. But it still does not differentiate between which is the active or not.
In regards to your script, you can continue to use Sleep 10000, so check every 10s. But what if you want to read something quickly in say MSN/Notepad etc. It will still trigger the event and closes all IE processes.
If you want to stick with your method:
| Code: | szApp2Close = IEFrame
Loop
{
Sleep 10000
Winget, NoCloseID, id, A
WinGet, id, list,,, Program Manager
Loop, %id%
{
nID := id%A_Index%
WinGetClass, nClass, ahk_id %nID%
;msgbox % nclass
if (nID != NoCloseID) && (nClass = szApp2Close)
Winclose, ahk_id %nID%
}
}
return | But I would remove the Loop and replace it with a hotkey. But it is whatever you feel comfortable.
Another direction you can take is to stuff IE and use firefox or many other wonderful gecko based browser. Then you don't need the script at all.
Good luck  _________________
546F206C69766520
6973204368726973742C0D746F2064696520
6973206761696E2E0D285068696C20313A323129 |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|