Adds a window specification to a window group, creating the group if necessary.

GroupAdd, GroupName [, WinTitle, WinText, Label, ExcludeTitle, ExcludeText]



GroupName The name of the group to which to add this window specification. If the group doesn't exist, it will be created.

The title or partial title of the target window(s). It can be blank. Note: Although SetTitleMatchMode and DetectHiddenWindows do not directly affect the behavior of this command, they do affect the behavior of commands such as GroupActivate and GroupClose.

To use a window class, specify ahk_class ExactClassName (shown by Window Spy). To use a process identifier (PID), specify ahk_pid %VarContainingPID%.

In v1.0.30+, To use a window's unique ID number, specify ahk_id %VarContainingID%. To use a window group, specify ahk_group GroupName (i.e. groups may contain other groups).

The search can be narrowed by specifying multiple criteria. For example: My File.txt ahk_class Notepad

WinText If present, this parameter must be a substring from a single text element of the target window (as revealed by the included Window Spy utility). Hidden text elements are detected if DetectHiddenText is ON at the time that GroupActivate, GroupDeactivate, and GroupClose are used.
Label The label of a subroutine to run if no windows matching this specification exist when the GroupActivate command is used. The label is jumped to as though a Gosub had been used. Omit or leave blank for none.
ExcludeTitle Windows whose titles include this value will not be considered.
ExcludeText Windows whose text include this value will not be considered.



Each use of this command adds a new rule to a group. In other words, a group consists of a set of criteria rather than a fixed list of windows. Later, when a group is used by a command such as GroupActivate, each window on the desktop is checked against these criteria. If a window matches any of the criteria, it is considered a match.

A window group is typically used to bind together a collection of related windows, which is useful for tasks that involve many related windows, or an application that owns many subwindows. For example, if you frequently work with many instances of a graphics program or text editor, you can use GroupActivate on a hotkey to visit each instance of that program, one at a time, without having to use alt-tab or task bar buttons to locate them.

Since the entries in each group need to be added only once, this command is typically used in the auto-execute section of the script (the part at the top that occurs prior to the first hotkey label). Attempts to add duplicate entries to a group are ignored.

To include all windows in a group (except the special Program Manager window), use this example:
GroupAdd, AllWindows ; In versions prior to, use the next line instead.
GroupAdd, AllWindows, , , , Program Manager

In v1.0.30+, all windowing commands can operate upon a window group by specifying ahk_group MyGroupName for the WinTitle parameter. The commands WinMinimize, WinMaximize, WinRestore, WinHide, WinShow, WinClose, and WinKill will act upon all the group's windows. By contrast, the other window commands such as WinActivate and IfWinExist will operate only upon the topmost window of the group.



GroupActivate, GroupDeactivate, GroupClose



; In the autoexecute section at the top of the script:
GroupAdd, MSIE, ahk_class IEFrame ; Add only Internet Explorer windows to this group.
return ; End of autoexecute section.

; Assign a hotkey to activate this group, which traverses
; through all open MSIE windows, one at a time (i.e. each
; press of the hotkey).
Numpad1::GroupActivate, MSIE, r

; Here's a more complex group for MS Outlook 2002.
; In the autoexecute section at the top of the script:
SetTitleMatchMode, 2
GroupAdd, mail, Message - Microsoft Word ; This is for mails currently being composed
GroupAdd, mail, - Message ( ; This is for already opened items
; Need extra text to avoid activation of a phantom window:
GroupAdd, mail, Advanced Find, Sear&ch for the word(s)
GroupAdd, mail, , Recurrence:
GroupAdd, mail, Reminder
GroupAdd, mail, - Microsoft Outlook
return ; End of autoexecute section.

Numpad5::GroupActivate, mail ; Assign a hotkey to visit each Outlook window, one at a time.