# GroupAdd

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

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

### Parameters

GroupName | The name of the group to which to add this window specification. If the group doesn't exist, it will be created. Group names are not case sensitive.
WinTitle | A window title or other criteria identifying the target window. See WinTitle.
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 group (or this window specification prior to AHK_L 54) 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.

### Remarks

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 each of these criteria. If a window matches one of the criteria in the group, it is considered a match.

Although SetTitleMatchMode and DetectHiddenWindows do not directly affect the behavior of this command, they do affect the other group commands such as GroupActivate and GroupClose. They also affect the use of ahk_group in any other command's WinTitle.

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 (top part of the script). 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

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. To instead act upon only the topmost window, follow this example:

    WinHide % "ahk_id " . WinExist("ahk_group MyGroup")

By contrast, the other window commands such as WinActivate and IfWinExist will operate only upon the topmost window of the group.

### Related

GroupActivate, GroupDeactivate, GroupClose

### Examples

    ; 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.