Page 1 of 1

Script suggestion - Inactive window  Topic is solved

Posted: 21 Apr 2017, 07:24
by Nuramz
I am looking for a code that can help to close inactive windows. My system gets too slow when lot of windows stay open. So thinking of a script that can close inactive windows based on time it remained inactive. A newbie, so need help.

Thanks,

Re: Script suggestion - Inactive window

Posted: 22 Apr 2017, 02:08
by Rohwedder
Hallo,
the script must be started before the windows.

Code: Select all

#Persistent
GroupAdd, DoNotCloseThisWindows, ahk_class Progman
GroupAdd, DoNotCloseThisWindows, ahk_class Shell_TrayWnd
LiveTime = 60000 ;Live Time in ms
TestInterval = 2000
Nr = 1
NrMax := 10 + LiveTime//TestInterval ;10 = tolerance
SetTimer, Testing, %TestInterval%
Return
Testing:
	WinGet, AktivID, ID, A
	IFWinNotActive, ahk_group DoNotCloseThisWindows
	{
		ID%Nr% := AktivID
		LastActiveTime%AktivID% := A_TickCount
	}
	Else
		ID%Nr% =
	Nr := (Nr=NrMax)? 1:Nr+1
	CloseID := ID%Nr%
	IF !CloseID
		Return
	If (CloseID <> ClosedId)
		If (LastActiveTime%CloseID% <= (A_TickCount - LiveTime))
		{
			WinClose, ahk_ID %CloseID%
			ClosedId := CloseId
		}
	Else ;the Window does not want to be closed!
		WinActivate, ahk_ID %ClosedID%
Return