Last active
March 31, 2020 16:13
-
-
Save rodjjo/5b4034ccbf26d681074fe6735af68020 to your computer and use it in GitHub Desktop.
Opens firefox and close any window that open after the first one. must replace firefox path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <MsgBoxConstants.au3> | |
#include <Array.au3> | |
#include <GUIConstantsEx.au3> | |
#include <StaticConstants.au3> | |
#include <WindowsConstants.au3> | |
#include <WinAPISysWin.au3> | |
Func RunWaitFirefox() | |
Run('D:\Mozilla Firefox\firefox.exe') | |
Sleep(1000) | |
while True | |
local $ff = WinList ("[CLASS:MozillaWindowClass]") | |
if $ff[0][0] <> 0 then | |
ExitLoop | |
endif | |
Sleep(1000) | |
wend | |
Beep(1000, 200) | |
EndFunc | |
RunWaitFirefox() | |
Func GetTopWindow($handle) | |
local $result = $handle | |
While True | |
if _WinAPI_GetParent($result) = 0 then | |
ExitLoop | |
EndIf | |
$result = _WinAPI_GetParent($result) | |
WEnd | |
return $result | |
EndFunc | |
Func GetTopMostFirefoxWindows() | |
local $result = WinList ("[CLASS:MozillaWindowClass]") | |
For $i = 1 To $result[0][0] | |
$result[$i][1] = GetTopWindow($result[$i][1]) | |
Next | |
return $result | |
EndFunc | |
$firefoxWindows = GetTopMostFirefoxWindows() | |
Func IsAboutBlank($handle) | |
return WinGetTitle($handle) = 'Mozilla Firefox' | |
EndFunc | |
Func ShouldCloseWindow($handle) | |
For $i = 1 To $firefoxWindows[0][0] | |
If $firefoxWindows[$i][1] = $handle Then | |
return false | |
EndIf | |
Next | |
if IsAboutBlank($handle) then | |
return True | |
EndIf | |
local $size = WinGetPos($handle) | |
if @error <> 0 then | |
return True | |
endif | |
local $centerX = $size[0] + ($size[2] / 2) | |
local $centerY = $size[1] + ($size[3] / 2) | |
if (($centerY < 0) or ($centerX < 0) or ($centerX > @DesktopWidth) or ($centerY > @DesktopHeight)) _ | |
and ($centerX > -1200 ) and ($centerY > -1200) Then | |
return True | |
EndIf | |
return $size[2] > 800 and $size[3] > 600 | |
EndFunc | |
Func CloseFirefoxWindows() | |
local $currentWindows = GetTopMostFirefoxWindows() | |
local $hasWindowToClose = False | |
For $i = 1 To $currentWindows[0][0] | |
if ShouldCloseWindow($currentWindows[$i][1]) then | |
$hasWindowToClose = True | |
ExitLoop | |
EndIf | |
Next | |
if $hasWindowToClose Then | |
Sleep(500) | |
EndIf | |
For $i = 1 To $currentWindows[0][0] | |
if ShouldCloseWindow($currentWindows[$i][1]) then | |
WinClose($currentWindows[$i][1]) | |
Beep(2000, 100) | |
EndIf | |
Next | |
if $currentWindows[0][0] = 0 Then | |
Exit(0) | |
EndIf | |
EndFunc | |
While true | |
Sleep(1000) | |
CloseFirefoxWindows() | |
wend |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment