AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Add exceptions to Close All Windows?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Knowbodynow



Joined: 26 Jun 2007
Posts: 35

PostPosted: Mon Jul 02, 2007 3:09 am    Post subject: Add exceptions to Close All Windows? Reply with quote

Hello,

I'm a total beginner when it comes to AutoHotkey and not very well up on coding in general. I found the following code that closes all windows:

Code:
;====CLOSE ALL WINDOWS====

+#BackSpace::
WinGet, id, list, , , Program Manager
Loop, %id%
{
   StringTrimRight, this_id, id%a_index%, 0
   WinGetTitle, this_title, ahk_id %this_id%
   winclose,%this_title%
}
Return

Can anyone modify this code so that it only closes down windows open on the desktop. Currently it closes down background programs as well. Alternatively, is it possible to add exceptions so that this code closes everything but certain programs?

Thanks,

CaH
Back to top
View user's profile Send private message
Knowbodynow



Joined: 26 Jun 2007
Posts: 35

PostPosted: Sun Jul 15, 2007 6:11 am    Post subject: Reply with quote

Hello, does anyone have an answer for how to do this? I want to close all open windows only.

Thanks,

CaH
Back to top
View user's profile Send private message
Rhys



Joined: 17 Apr 2007
Posts: 721
Location: Florida

PostPosted: Mon Jul 16, 2007 2:27 pm    Post subject: Reply with quote

Knowbodynow wrote:
Hello, does anyone have an answer for how to do this? I want to close all open windows only.

Thanks,

CaH


I'm confused... How would you close a window that is not open?
_________________
[Join IRC!]
Back to top
View user's profile Send private message
aCkRiTe



Joined: 21 Jul 2006
Posts: 502

PostPosted: Mon Jul 16, 2007 2:55 pm    Post subject: Re: Add exceptions to Close All Windows? Reply with quote

Knowbodynow wrote:

Can anyone modify this code so that it only closes down windows open on the desktop. Currently it closes down background programs as well.

Im not exactly sure what you mean here. What do you mean by background programs?

Knowbodynow wrote:

Alternatively, is it possible to add exceptions so that this code closes everything but certain programs?

Yes its possible...


Code:

;====CLOSE ALL WINDOWS====

MatchList = AutoHotKey Help,Untitled - Notepad,Calculator

+#BackSpace::
WinGet, ID, List, , , Program Manager
Loop, %ID%
   {
      StringTrimRight, This_ID, ID%A_Index%, 0
      WinGetTitle, This_Title, ahk_id %This_ID%
      If This_Title in %MatchList%
         Continue
      WinClose, %This_Title%
   }
Return




HTH...
Back to top
View user's profile Send private message
Knowbodynow



Joined: 26 Jun 2007
Posts: 35

PostPosted: Tue Jul 17, 2007 8:10 am    Post subject: Reply with quote

Thank you, that's great. I can understand how that works. I've done a little programming of CorelDraw Macros in VBS. I still need to get used to the idea of enclosing variables with percentage signs.

Regarding background programs I use Creative Elements Power Tools. Their Start Up program is launched on boot up via the Start Folder. It doesn't appear on the toolbar or in the tray. It was getting closed down by the original code. Now I can add it as an exception and prevent it from being closed down.

Thanks again,

CaH
Back to top
View user's profile Send private message
Knowbodynow



Joined: 26 Jun 2007
Posts: 35

PostPosted: Tue Jul 17, 2007 5:19 pm    Post subject: Reply with quote

Looks like I spoke two soon, the method isn't working for me. It seems I need to use an exact window title and I need to be able to find partial matches. Also with applications like Calculator this was still maximized so something is not right somewhere.

Does anyone have any other suggestions?

Thanks,

CaH
Back to top
View user's profile Send private message
silveredge78



Joined: 25 Jul 2006
Posts: 381
Location: Midwest, USA

PostPosted: Tue Jul 17, 2007 5:34 pm    Post subject: Reply with quote

Perhaps a modification of using Process name and id, rather than window name and id? I would think that the background application wouldn't have an actual window to pull that information from properly.
_________________
SilverEdge78
Back to top
View user's profile Send private message
aCkRiTe



Joined: 21 Jul 2006
Posts: 502

PostPosted: Tue Jul 17, 2007 8:39 pm    Post subject: Reply with quote

what does your matchlist look like? Read this about a matchlist...

Quote:
A comma-separated list of strings, each of which will be compared to the contents of Var for a match. Any spaces or tabs around the delimiting commas are significant, meaning that they are part of the match string. For example, if MatchList is set to ABC , XYZ then Var must contain either ABC with a trailing space or XYZ with a leading space to cause a match.


Is it still closing windows that you dont want it to, even though they are in the matchlist?
Back to top
View user's profile Send private message
Knowbodynow



Joined: 26 Jun 2007
Posts: 35

PostPosted: Wed Jul 18, 2007 12:24 am    Post subject: Reply with quote

aCkRiTe wrote:

Is it still closing windows that you dont want it to, even though they are in the matchlist?

Yes, I copied and pasted the code you gave and it closed calculator when it was running.

My last post may also have been confusing because I mentioned that Calculator was being maximized. I'm using two versions of the script. I replace WinClose with WinMaximize. When I wrote about Calculator being maximized I was referring to the other version. Sorry about that. Basically, the matchlist is being ignored and all windows are being processed whether the command is WinClose or WinMaximize

CaH
Back to top
View user's profile Send private message
aCkRiTe



Joined: 21 Jul 2006
Posts: 502

PostPosted: Wed Jul 18, 2007 1:15 am    Post subject: Reply with quote

Are you using just the script I gave or is there more to your script? Im not too sure why this is not working for you cause I have tested the script.

Maybe try adding MsgBox instead of WinClose and leave the matchlist empty. Run the script. Then get the exact title that you want to add to the matchlist that it gives you in the message box and then add that title to the matchlist and then try the script again with the msgbox and see if you get a message box with that title. Hope that makes a little sense...
Back to top
View user's profile Send private message
Knowbodynow



Joined: 26 Jun 2007
Posts: 35

PostPosted: Wed Jul 18, 2007 2:08 am    Post subject: Reply with quote

You are right, I ran the script by itself and it worked, calculator was not closed. But it appears that if I have anything else in the script it fails to work. E.g.:

Code:

^#s:: Run C:\Program Files\Spybot - Search & Destroy\SpybotSD.exe

;====CLOSE ALL WINDOWS====

MatchList = AutoHotKey Help,Untitled - Notepad,Calculator

+#BackSpace::
WinGet, ID, List, , , Program Manager
Loop, %ID%
   {
      StringTrimRight, This_ID, ID%A_Index%, 0
      WinGetTitle, This_Title, ahk_id %This_ID%
      If This_Title in %MatchList%
         Continue
      WinClose, %This_Title%
   }
Return


With the shortcut key to spybot R&D present Calcultor is closed when the script is run. I don't understand why this is the case. I wonder if there is a way around it as I want to be able to open programs with shortcut keys.

CaH
Back to top
View user's profile Send private message
Superfraggle



Joined: 02 Nov 2004
Posts: 846
Location: London, UK

PostPosted: Wed Jul 18, 2007 2:12 am    Post subject: Reply with quote

I believe the matchlist is not being looked at, move the matchlist to the very beginning of the whole script to the auto execute part of the script.
_________________
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle
Back to top
View user's profile Send private message MSN Messenger
aCkRiTe



Joined: 21 Jul 2006
Posts: 502

PostPosted: Wed Jul 18, 2007 2:30 am    Post subject: Reply with quote

Superfraggle wrote:
I believe the matchlist is not being looked at, move the matchlist to the very beginning of the whole script to the auto execute part of the script.


I think he is correct!


should look like this:

Code:

MatchList = AutoHotKey Help,Untitled - Notepad,Calculator

^#s:: Run C:\Program Files\Spybot - Search & Destroy\SpybotSD.exe

;====CLOSE ALL WINDOWS====

+#BackSpace::
WinGet, ID, List, , , Program Manager
Loop, %ID%
   {
      StringTrimRight, This_ID, ID%A_Index%, 0
      WinGetTitle, This_Title, ahk_id %This_ID%
      If This_Title in %MatchList%
         Continue
      WinClose, %This_Title%
   }
Return
Back to top
View user's profile Send private message
Knowbodynow



Joined: 26 Jun 2007
Posts: 35

PostPosted: Wed Jul 18, 2007 1:03 pm    Post subject: Reply with quote

Thanks everyone and especially Superfraggle. I moved the matchlist to the top of the entire script and it now works correctly.

Cheers

CaH
Back to top
View user's profile Send private message
rodfell



Joined: 05 Oct 2007
Posts: 57
Location: Bundaberg (Bundy), Qld, Australia

PostPosted: Sat Nov 10, 2007 1:05 pm    Post subject: stringtrimright Reply with quote

i don't understand why the stringtrimright exists. I gather you want to make this_id:=id%a_index%
Code:


MatchList = AutoHotKey Help,Untitled - Notepad,Calculator

^#s:: Run C:\Program Files\Spybot - Search & Destroy\SpybotSD.exe

;====CLOSE ALL WINDOWS====

+#BackSpace::
WinGet, ID, List, , , Program Manager
Loop, %ID%
   {
      this_id:=id%a_index%
      WinGetTitle, This_Title, ahk_id %This_ID%
      If This_Title in %MatchList%
         Continue
      WinClose, %This_Title%
   }
Return
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group