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, WinText, ExcludeTitle, ExcludeText

Specify for WinTitle a window title or other criteria to identify the target window and/or for WinText a substring from a single text element of the target window (as revealed by the included Window Spy utility).

ExcludeTitle and ExcludeText can be used to exclude one or more windows by their title or text. Their specification is similar to WinTitle and WinText, except that ExcludeTitle does not recognize any criteria other than the window title.

Window titles and text are case-sensitive. Although DetectHiddenWindows, DetectHiddenText and SetTitleMatchMode 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.

Label

If blank or omitted, no label will be used. Otherwise, specify 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.

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.

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 operate upon all the group's windows. To instead operate upon only the topmost window, follow this example:

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

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

GroupActivate, GroupDeactivate, GroupClose

Examples

Press a hotkey to traverse all open MSIE windows.

; 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

Press a hotkey to visit each MS Outlook 2002 window, one at a time.

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

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