
Removing windows from a group or deleting a group ?


There will probably be better group handling commands in a future version.

I was looking for a GroupReset (or GroupClear) or a GroupRemove (for a single rule removal)
So, just posted here to vote.

Just got to this thread by a search for this type of command.
I was looking for a GroupReset (or GroupClear) or a GroupRemove (for a single rule removal)
So, just posted here to vote.
me too


I've been thinking of solving this, because I needed a "remove" command too.There's currently no way to do it, so the usual work-around would be to create a new group.
Although having a Group Remove command etc. in AHK would be easier.
The main problem is that we don't have access to the list of criteria of GroupName from GroupAdd.
So it's necessary to keep track of those.
I tried to put it all in the function WinGroup, so I don't have to worry about all this. I hope it can be useful.
WinGroup commands:
WinGroup("add",GroupName,<Window Parameters>) : add Window to GroupName
WinGroup("remove",GroupName,<Window Parameters>) : removes Window from GroupName
WinGroup("clear",GroupName) : deletes all windows from GroupName (group GroupName itselfs still exists)
Limitations and Remarks:
-You have to use always WinGroup() to keep track of added windows.
-You have to use a variable for GroupName instead of a string constant like GroupName in AHK GroupAdd.
I.e. you have to use also "ahk_group %TestGroup%". So don't use variable GroupName for other purpose then function WinGroup.
-There's an absolute max. of 26 different groups (DummyA,DummyB,...,DummyZ) (Current script only 10 groups)
This can be solved too by changing the code, but 26 groups seems a lot already.
-WinGroup remove command is based on making new groups (groupnames) after each remove. Therefore old groups still exist in memory.
; -------- Testscript for WinGroup() --------------- ; Remark: testscript will close all Calculator and NotePad windows at the end! Run, Notepad.exe Run, Calc.exe TestGroup:= "" ; WinGroup function can take wrong GroupName, if TestGroup accidently contains already e.g. "DummyA" ; Very small chance TestGroup contains e.g. "DummyA", but just to be sure initialize TestGroup. MsgBox,262144,%TestGroup%, Minimize now NotePad and Calculator, and continue. WinGroup("add",TestGroup,"ahk_class Notepad") WinGroup("add",TestGroup,"ahk_class SciCalc") WinRestore, ahk_group %TestGroup% MsgBox,262144,%TestGroup%, NotePad and Calculator are restored. `nMinimize now NotePad and Calculator, and continue. WinGroup("remove",TestGroup,"ahk_class SciCalc") WinRestore, ahk_group %TestGroup% MsgBox,262144,%TestGroup%,Only Notepad will be restored. ; variable TestGroup is changed by WinGroup("remove",...) WinGroup("add",TestGroup,"ahk_class Notepad") ; test that existing criteria will not be added again WinGroup("add",TestGroup,"ahk_class SciCalc") WinClose, ahk_group %TestGroup% MsgBox,262144,%TestGroup%,NotePad and Calculator are closed. ; variable TestGroup is changed by WinGroup("remove",...) WinGroup("clear",TestGroup) ; variable TestGroup is changed by WinGroup("clear",...) Run, Notepad.exe F10:: WinRestore, ahk_group %TestGroup% ; test for clear TestGroup F11:: WinGroup("add",TestGroup,"ahk_class Notepad") ; test for clear TestGroup F9::ExitApp Return ; -------- End Testscript for WinGroup() --------------- WinGroup(Cmd,ByRef GroupName,WinTitle= "",WinText= "",Label= "",ExcludeTitle= "",ExcludeText= "") { Static WinGroupA:= "",WinGroupB:= "",WinGroupC:= "",WinGroupD:= "",WinGroupE:= "" ; list of windows in the group Static WinGroupF:= "",WinGroupG:= "",WinGroupH:= "",WinGroupI:= "",WinGroupJ:= "" ; list of windows in the group Static MaxGroups:= 10,FreeGroupIndex:= 1 ; first not used Group number If (Cmd= "add") { If (FreeGroupIndex> MaxGroups) { MsgBox,48,%A_ScriptName% - %A_thisFunc%,MaxGroups= %MaxGroups%! Return true ; error } WinGroupName:= WinGroupName(GroupName) StringReplace, GroupIndex, WinGroupName, Dummy If errorlevel { ; ->new group If (FreeGroupIndex< 27) { GroupIndex:= Chr(64 + FreeGroupIndex) GroupName:= "Dummy" GroupIndex "1" ; -> GroupName= DummyA1 (or DummyB1,DummyC1,...) FreeGroupIndex++ } else { MsgBox,48,%A_ScriptName% - %A_thisFunc%,Max. 26 groups allowed! Return true } } AddParameters:= WinTitle "," WinText "," Label "," ExcludeTitle "," ExcludeText "|" If InStr(WinGroup%GroupIndex%,AddParameters) Return false ; don't add already existing windows else { WinGroup%GroupIndex% .= AddParameters GroupAdd, %GroupName%,%WinTitle%,%WinText%,%Label%,%ExcludeTitle%,%ExcludeText% } Return false } If (Cmd= "remove" || Cmd= "clear") { WinGroupName:= WinGroupName(GroupName,NewNameIndex) ; e.g. WinGroup("DummyB21",...) ->DummyB and 21 StringReplace, GroupIndex, WinGroupName, Dummy NewNameIndex++ ; ->GroupName DummyA1 becomes DummyA2 for remove command GroupName= %WinGroupName%%NewNameIndex% ; assign new content (=name) to GroupName ; I.e. return to ByRef GroupName parameter too WinGroupTmp:= WinGroup%GroupIndex% WinGroup%GroupIndex%:= "" ; clear to make new list by WinGroup("add",...) If (Cmd= "clear") Return false ; finished re-add nothing to GroupName RemoveParameters= %WinTitle%,%WinText%,%Label%,%ExcludeTitle%,%ExcludeText%| StringReplace, WinGroupTmp, WinGroupTmp, %RemoveParameters% RemoveError:= errorlevel Loop, parse,WinGroupTmp,| { If (A_loopField= "") Continue Loop, parse,A_loopField,csv { If (A_index= 1) ReAddTitle:= A_loopField else If (A_index= 2) ReAddText:= A_loopField else If (A_index= 3) ReAddLabel:= A_loopField else If (A_index= 4) ReAddExcludeTitle:= A_loopField else If (A_index= 5) ReAddExcludeText:= A_loopField } WinGroup("add",GroupName,ReAddTitle,ReAddText,ReAddLabel,ReAddExcludeTitle,ReAddExcludeText) } Return RemoveError } } WinGroupName(GroupName,ByRef NameIndex= "") { ; Makes from e.g. DummyB23 -> AlphaName= DummyB NameIndex= 23 Loop { Char:= SubStr(GroupName,1 - A_index,1) If Char is alpha { AlphaName:= SubStr(GroupName,1,StrLen(GroupName) -A_index+1) NameIndex:= SubStr(GroupName,2 - A_index) ; Here always A_index > 1 (GroupName starts with e.g. DummyB1) Break } } Return AlphaName }

Great script. Not quite the functionality I need for my application, but it definately works in other cases.

I'm using the group features in NiftyWindows (<!-- m -->http://www.enovatic....s/niftywindows/<!-- m -->).
It lets you add random windows to a group mapped to a hotkey.
Sometimes I wish I could remove a window from a group, but I can't.
I tried to modify NiftyWindows to use the WinGroup functions in this thread,
but WinGroup didn't seem to like the variable GroupNames of NiftyWindows.
Anyway -- I'd use GroupDelete if it was there.

Until then I believe it should be specified in the help file at the GroupAdd/GroupActivate section that Groups do not behave like normal variables.
Just spent a lot of minutes trying to clear a group in vain :?
________
ARIZONA DISPENSARY

More seriously I have seen worse revival.
And since a search only revealed that thread as relevant, I didn't mind reviving it.
________
Maine marijuana dispensaries

I too second the request for GroupDelete, and for GroupExclude, GroupName, WindowTitle (to exclude a window from group).

Hi,
I too second the request for GroupDelete, and for GroupExclude, GroupName, WindowTitle (to exclude a window from group).
I third that.

How about this: if you want to create a group called "mywindows", use "mywindows%group_counter%", where group_counter is set to 0. If you want to clear this group, increment group_counter and add windows to this group again.
