Script that finds minimized windows and restores them

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
thebunnyrules
Posts: 18
Joined: 29 Mar 2015, 04:31

Script that finds minimized windows and restores them

22 Apr 2017, 15:26

Hi,

I'm using on open source software windows switcher called SmallWindows but it doesn't show minimized windows which is kind of a deal breaker.

I wanted to fix it by making an AHK script that would ensure that all windows are not minimized before I initiate the window switching.

I tried the following script already that I copied off of one of the AHK threads:

Code: Select all

WinGet, WinList, List
Loop % WinList
WinMaximize % "ahk_id " WinList%A_Index%
This is a good start but still not ideal, as it will maximize all windows regardless of state. This is a bit laggy but also, in some cases I may not want maximized windows, like when I have windows that are tiled for example.

I'm trying to write a script that will make a list of windows and perform a WinGet MinMax test on each window in the list to figure out if it's minimized or not. It would then do a WinRestore for only the windows that have a MinMax state of -1. This is what I have so far:

Code: Select all

WinGet, WinList, List
Loop % WinList
WinGet, WinState, MinMax, % "ahk_id " WinList%A_Index%
If ( WinState < 0 )
WinRestore % "ahk_id " WinList%A_Index%
sleep 100
Exit
It's not work but I don't know what I'm doing wrong. Could someone give me some feedback?

Also, is there a way of making the script go faster, like increasing the scripts priortity or calling some kind of DLL hook?
Last edited by thebunnyrules on 22 Apr 2017, 15:33, edited 1 time in total.
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Script that finds minimized windows and restores them

22 Apr 2017, 15:32

In the second code, you need a block for your Loop.

If you fix that, it should work. I don't see any other errors jumping out at me.
thebunnyrules
Posts: 18
Joined: 29 Mar 2015, 04:31

Re: Script that finds minimized windows and restores them

22 Apr 2017, 15:40

Thanks Exaskryz, that worked perfectly. This is what I have so far:

Code: Select all

WinGet, WinList, List
Loop % WinList {
WinGet, WinState, MinMax, % "ahk_id " WinList%A_Index%
If ( WinState < 0 )
WinRestore % "ahk_id " WinList%A_Index%
}
Exit
Is there anyway of speeding it up? Give it a higher priority or dll hook?
thebunnyrules
Posts: 18
Joined: 29 Mar 2015, 04:31

Re: Script that finds minimized windows and restores them

22 Apr 2017, 16:53

If I want to re-minimize all the minimized windows after the switching is finished, is there a way I can add the elements of WinList with a MinMax state of -1 to a new list that I would call, say, MinList. I tried to make an array called MinList and to have the script copy the WinList entries with -1 to it in the if loop:

Code: Select all

	+!t::
		MinList := Object()
		ArrayCount := 0	
		WinGet, WinList, List
		Loop % WinList {
			WinGet, WinState, MinMax, % "ahk_id " WinList%A_Index%  
		If ( WinState < 0 ) 
			WinRestore % "ahk_id " WinList%A_Index%
			ArrayCount += 1
			MinList[ArrayCount] := WinList%A_Index%
		} 

		; Application Switcher Block goes here
		Sleep, 5000

		; this should reminimize all the relevant windows but it doesn't
		; what am i doing wrong?
		Loop % MinList {
			WinMinimize % "ahk_id " MinList%A_Index%
			}
	Exit
This is what I have so far, I made this little test script that unminimizes minimized windows, adds them to the MinList array, waits for 5 seconds and reminimizes the MinList array. It's not working. Anyone has any idea what I'm doing wrong?

Thanks so for all the help you've given so far guys. I appreciate it.
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Script that finds minimized windows and restores them

22 Apr 2017, 20:38

Again, double check blocks.

I don't know what "doesn't working" means. Because that code looks like it should winrestore your minimized windows, but then minimize all your windows (as arraycount is incremented no matter what WinState is, and the array is added onto as well). If you're not getting that behavior, then I'm missing something when I'm reviewing (but not testing) the code, and I'd like you to describe what is going wrong for you.

Edit: Oh yeah, .length() method for your array is what's necessary in your loop. MinList is an object, not a number. So the Loop MinList at the end is skipped I believe because it interprets it as a value of 0.
Last edited by Exaskryz on 23 Apr 2017, 08:56, edited 1 time in total.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Script that finds minimized windows and restores them

23 Apr 2017, 03:10

thebunnyrules wrote:

Code: Select all

 ; this should reminimize all the relevant windows but it doesn't
 ; what am i doing wrong?
 Loop % MinList {
	 WinMinimize % "ahk_id " MinList%A_Index%
 }
The answer is,

Code: Select all

 MinList := Object()
See Objects, object, especially, see Push(...) and Length(), consider using a for loop, also, for speed, see SetWinDelay.

Additionally. as Exaskryz already said, look at your blocks and read the documentaion about it. Hint: If ( WinState < 0 )
thebunnyrules
Posts: 18
Joined: 29 Mar 2015, 04:31

Re: Script that finds minimized windows and restores them

23 Apr 2017, 14:47

Hi Guys, thanks for your help. I'm not sure I'm understanding everything that's been said but I'm going to have a read through the methods and sections mentioned in the comments and get back to you.

Herglef, just to clarify, are you saying that my having set

MinList := Object()

at the beginning of the script was contributing to the problem because Object() is the wrong type?

Here's what I have so far after fixing the block error mentioned above:

Code: Select all

	+!t::
		MinList := Object()
		ArrayCount := 0	
		WinGet, WinList, List
		Loop % WinList {
			WinGet, WinState, MinMax, % "ahk_id " WinList%A_Index%  
		If ( WinState < 0 ) {
			WinRestore % "ahk_id " WinList%A_Index%
			ArrayCount += 1
			MinList[ArrayCount] := WinList%A_Index%
			}
		} 

		; Application Switcher Block goes here
		Sleep, 5000

		Loop % MinList {
			WinMinimize % "ahk_id " MinList%A_Index%
			}
			
	Exit
		;*/
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Script that finds minimized windows and restores them

23 Apr 2017, 15:39

thebunnyrules wrote:are you saying that my having set
MinList := Object()
at the beginning of the script was contributing to the problem because Object() is the wrong type?
Not really, because you do not use the MinList object/array after you filled it. MinList:=Object() gives you an actual array, but you are using a pseudo-array, MinList%A_Index% which are just variables, which has not been given any values.

Your blocks seems ok now :thumbup:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, jameswrightesq and 283 guests