Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Close all windows of same type as current foreground window


  • Please log in to reply
3 replies to this topic
some matthias
  • Guests
  • Last active:
  • Joined: --
Hi.
I don't know if this is possible.
I would like to have a hotkey for closing all windows that are of the same type as te current foreground window.
For example: if the current active window is a cmd i want to close with one hotkey alls cmd windows running.

Would be a great addition to my autohotkeys.

thx & greets.

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
First you need to choose a way to identify windows of "the same type"
You can use title (the end of a firefox window ends in "- Mozilla Firefox") or class (ahk_class something). Get the class of the active window with WinGetClass, or the title ending with WinGetTitle, InStr(), and SubStr(). Then use "WinGet, List" and Loop through each window to see if it meets the same criteria as the formerly active one. If so, WinClose it.

If you get stuck post your code in
[code][/code]
tags and we'll help out. Good luck :wink:

Gogo
  • Guests
  • Last active:
  • Joined: --
Windows that are of the same type have the same WinClass. To close all windows of the same type they should be added to a group.

AHK Help/Index/WinClose:
This command operates only upon the topmost matching window except when WinTitle is ahk_group GroupName, in which case all windows in the group are affected.

This script creates a group with a name similar to the WinClass of the active window and adds this class into it.
StringReplace command replaces eventual spaces in the class as they are illegal in the group name.
F1::
  WinGetClass class, A
  StringReplace grp, class, %A_Space%, _ , All
  GroupAdd %grp%, ahk_class %class%
  WinClose ahk_group %grp%
  return


wilcofan
  • Members
  • 10 posts
  • Last active: Mar 22 2016 03:37 PM
  • Joined: 17 Jan 2014

Excellent script thank you Gogo.