Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Removing windows from a group or deleting a group ?


  • Please log in to reply
17 replies to this topic
uXs
  • Members
  • 4 posts
  • Last active: Apr 23 2006 03:36 PM
  • Joined: 22 Apr 2006
Hi. I was wondering if it's possible to remove windows from a group or even outright deleting a group ?

evl
  • Members
  • 1237 posts
  • Last active: Oct 20 2010 11:41 AM
  • Joined: 24 Aug 2005
Very good question - I'd not used groups enough to notice the lack of a GroupDelete option or similar. The group name doesn't seem to act like an ordinary variable so I think it's a feature request (in the very least GroupReset or similar to clear the group would allow the group name to be re-used/re-built).

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
There's currently no way to do it, so the usual work-around would be to create a new group. Each group takes up very little memory, so that won't be a concern for most usages.

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

Icarus
  • Members
  • 851 posts
  • Last active: Jan 02 2012 11:17 AM
  • Joined: 24 Nov 2005
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.

adamrgolf
  • Members
  • 442 posts
  • Last active: May 22 2017 09:16 PM
  • Joined: 28 Dec 2006

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 :)

bobobobo
  • Guests
  • Last active:
  • Joined: --
I agree, a groupDelete would be great.

Peter
  • Members
  • 448 posts
  • Last active: Jan 15 2010 05:41 AM
  • Joined: 30 Dec 2005

There's currently no way to do it, so the usual work-around would be to create a new group.

I've been thinking of solving this, because I needed a "remove" command too.
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
}


  • Guests
  • Last active:
  • Joined: --
@ Peter:

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

rhall
  • Members
  • 1 posts
  • Last active: Aug 08 2006 12:49 PM
  • Joined: 02 May 2006
I need GroupDelete too.

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.

lilalurl.T32
  • Members
  • 391 posts
  • Last active: Jul 05 2011 03:39 PM
  • Joined: 17 May 2007
I too would not mind a native AHK support for some GroupDelete/GroupReset.

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

QSQCaito
  • Members
  • 7 posts
  • Last active: Jul 19 2008 02:53 AM
  • Joined: 08 Jul 2008
Look at dates pal, huge revival!

lilalurl.T32
  • Members
  • 391 posts
  • Last active: Jul 05 2011 03:39 PM
  • Joined: 17 May 2007
Check my profile, my stats for forum necromancy are D20 + 15...:wink:

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

Roman
  • Members
  • 85 posts
  • Last active: May 27 2009 04:16 PM
  • Joined: 22 Oct 2008
Hi,

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

fincs
  • Moderators
  • 1662 posts
  • Last active:
  • Joined: 05 May 2007

Hi,

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


I third that.

daroc
  • Members
  • 23 posts
  • Last active: Apr 04 2012 10:13 PM
  • Joined: 05 Mar 2009
Maybe it's possible to use arrays to simulate clearing a group?
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.