AutoHotkey Community

It is currently May 26th, 2012, 3:36 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 15 posts ] 
Author Message
PostPosted: April 23rd, 2006, 2:54 pm 
Offline

Joined: April 22nd, 2006, 10:28 pm
Posts: 4
Hi. I was wondering if it's possible to remove windows from a group or even outright deleting a group ?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 23rd, 2006, 4:56 pm 
Offline

Joined: August 24th, 2005, 5:17 pm
Posts: 1237
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).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 25th, 2006, 12:17 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 27th, 2006, 5:44 pm 
Offline

Joined: November 24th, 2005, 8:16 am
Posts: 851
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 2nd, 2007, 11:26 am 
Offline

Joined: December 28th, 2006, 9:46 am
Posts: 440
Icarus wrote:
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 :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject: I agree
PostPosted: July 30th, 2007, 5:05 pm 
I agree, a groupDelete would be great.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 5th, 2007, 5:58 pm 
Offline

Joined: December 30th, 2005, 5:01 pm
Posts: 448
Chris wrote:
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.
Quote:
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.
Code:
   ; -------- 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
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 6th, 2007, 8:05 pm 
@ Peter:

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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 17th, 2007, 1:38 am 
Offline

Joined: May 2nd, 2006, 5:11 am
Posts: 1
Location: Austin, TX
I need GroupDelete too.

I'm using the group features in NiftyWindows (http://www.enovatic.org/products/niftywindows/).
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 17th, 2008, 7:07 pm 
Offline

Joined: May 17th, 2007, 6:03 pm
Posts: 391
Location: Titan
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


Last edited by lilalurl.T32 on February 11th, 2011, 9:38 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 17th, 2008, 7:53 pm 
Offline

Joined: July 8th, 2008, 5:49 am
Posts: 7
Look at dates pal, huge revival!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 17th, 2008, 8:06 pm 
Offline

Joined: May 17th, 2007, 6:03 pm
Posts: 391
Location: Titan
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


Last edited by lilalurl.T32 on February 11th, 2011, 9:38 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 12th, 2009, 3:54 pm 
Offline

Joined: October 22nd, 2008, 11:52 am
Posts: 85
Hi,

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

_________________
AutoHotKey


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 27th, 2009, 12:30 pm 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
Roman wrote:
Hi,

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


I third that.

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2009, 4:20 pm 
Offline

Joined: March 5th, 2009, 7:59 pm
Posts: 23
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.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 17 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group