Hi, I’m a beginner but not a lazy one…I have spent hours reading tutorials and looking at scripts but I can’t get the below to work.
1. Close all active windows of a certain type but keep most recently active window.
Copied script Internet script (apologies didn’t write who off to give credit- but thanks loads!)
;Close all explorer windows excepts the most active
^#X::
; List gets all ids starting from the topmost down
WinGet, OutList, List, ahk_classCabinetWClass
Loop, %OutList% {
if A_Index = 1
{ ; skip
Continue
}
WinClose, % "ahk_id " OutList%A_Index%
}
Return
Changed the script so does the same in MS Word and outlook and mozilla.
BUT doesn’t work in excel or sage accountancy software? For both it just closes all windows of excel/sage?
Excel
^#E::
; List gets all ids starting from the topmost down
WinGet, OutList, List, ahk_class XLMAIN
Loop, %OutList% {
if A_Index = 1
{ ; skip
Continue
}
WinClose, % "ahk_id " OutList%A_Index%
}
Return
Sage
The software homescreen window I want to keep active on left monitor and close all other sage windows which generally open on monitor 2 (just by chance which I prefer…..not had a go of resizing & moving positions yet).
Windows to close have class: ahk_class #32770
Homescreen window has different class (cant remember got screenshot on work pc.)
But they both the same ahk_exe, both types of windows.
Many Thanks
Hannah
Close all window type other than most recently active
-
- Posts: 53
- Joined: 01 Jun 2019, 09:02
Re: Close all window type other than most recently active
You can find out if the first in the list is the one you want to keep .Maybe the first listed one is not the correct one.
Code: Select all
WinGet, OutList, List, ahk_class XLMAIN
Loop, %OutList% {
WinGetTitle, title,% "ahk_id " OutList%A_Index%
z .=A_Index " " title "`n"
}
msgbox %z%
-
- Posts: 53
- Joined: 01 Jun 2019, 09:02
Re: Close all window type other than most recently active
Thank you very much. I will try it tomorrow at work.
-
- Posts: 53
- Joined: 01 Jun 2019, 09:02
Re: Close all window type other than most recently active
trust_me
Hi, thanks for the script but dont 100% understand what this scrit shows. When i run it with 2 blank excle docs open I get msg box msg:
1 Book2- Excel
2 Book1-Excel
Many Thanks
Hi, thanks for the script but dont 100% understand what this scrit shows. When i run it with 2 blank excle docs open I get msg box msg:
1 Book2- Excel
2 Book1-Excel
Many Thanks
Re: Close all window type other than most recently active
The code gives you the list of windows from the code : WinGet, OutList, List, ahk_class XLMAINClose all active windows of a certain type but keep most recently active window.
The first one in the list is the last active window . In de code you have been using you skipped the first entry : if A_Index = 1
so this one will not be closed.
You seem to suggest ( if i understood it correct ) that the window you want to stay is closed when you run your code , with the code i posted you can see which is on position 1 .If the window you wanted to stay is not position 1 it will be closed ( maybe it was not the last active window ) and you will need to make it the last active window or use another way of removing it from the list for example by using the exclude option in winclose command.
WinClose [, WinTitle, WinText, SecondsToWait, ExcludeTitle, ExcludeText]
You can use part of the title or text ( Window Spy will give you info for this )
-
- Posts: 53
- Joined: 01 Jun 2019, 09:02
Re: Close all window type other than most recently active
Thanks a lot, that definitely makes sense and thanks for the alternative with winclose and the exclude options. I’ll try it tomorrow at work.
Who is online
Users browsing this forum: No registered users and 332 guests