Closing 5 programs with 1 keyboard shortcut Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
DutchPete
Posts: 98
Joined: 03 Feb 2015, 03:59

Closing 5 programs with 1 keyboard shortcut

18 Feb 2015, 08:56

I always have 5 standard programs open, which I close at the end of the day. I want to be able to close them all at once with 1 keyboard shortcut.
I understand you have to create a Group for those programs, then a script to close that Group.
Can those 2 processes be incorporated in 1 script? If yes, I assume the 1st line of the script creates the group, the 2nd line closes the programs in the group. Would something like this fly if in 1 script:

!q::
GroupAdd MultiClose (thundebird.exe, evernote.exe) - the other 3 programs can be added to the row
WinClose, ahk_group, MultiClose
Return

If not, please advise.
Last edited by DutchPete on 18 Feb 2015, 09:08, edited 1 time in total.
User avatar
empardopo
Posts: 336
Joined: 06 Oct 2013, 12:50
Location: Spain
Contact:

Re: Closing 5 programs with 1 keyboard shortcut

18 Feb 2015, 09:07

Perhaps, this code can be useful for you

Code: Select all

Hotkey, ~k, killProc
return

killProc:
      Process, close, notepad.exe
      Process, close, thundebird.exe
      Process, close, evernote.exe
return
Greetings.
Everything is possible!
DutchPete
Posts: 98
Joined: 03 Feb 2015, 03:59

Re: Closing 5 programs with 1 keyboard shortcut

18 Feb 2015, 09:40

Thanks Empardopo, that works.
The Thunderbird one does not work. It is not really in the AHK scope, but then again, I have a .bat script to close Thunderbird for something else. It is a taskkill, but instead of writing thunderbird.exe I had to put thunderbird* because each time TB is openend it has a slightly different name.
I tried thunderbird* in your AHK script but it does not work. Is there an equivalent of thunderbird* for AHK that you know of?
lexikos
Posts: 6490
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Closing 5 programs with 1 keyboard shortcut

18 Feb 2015, 18:56

I would kill processes only as a last resort.

Code: Select all

; Create the group only once, with each app window on a separate line.
GroupAdd MultiClose, ahk_exe Notepad.exe
GroupAdd MultiClose, ahk_exe SciTE.exe

!q::
WinClose, ahk_group MultiClose  ; No comma between ahk_group and MultiClose.
; Note this closes the windows; it does not kill processes, so some apps
; might continue to run in the backgroud.
Return
If you know the window title and need a process ID, you can use the PID sub-command of WinGet.
DutchPete
Posts: 98
Joined: 03 Feb 2015, 03:59

Re: Closing 5 programs with 1 keyboard shortcut

19 Feb 2015, 03:32

Hi Lexikos, yes yours is probably a better solution for me because the kill process is an aggressive action. I tried your suggestion & it worked.
To close Thunderbird a sub-command is needed. Could you tell me how to do one?
User avatar
empardopo
Posts: 336
Joined: 06 Oct 2013, 12:50
Location: Spain
Contact:

Re: Closing 5 programs with 1 keyboard shortcut

19 Feb 2015, 04:28

DutchPete wrote:Thanks Empardopo, that works.
The Thunderbird one does not work. It is not really in the AHK scope, but then again, I have a .bat script to close Thunderbird for something else. It is a taskkill, but instead of writing thunderbird.exe I had to put thunderbird* because each time TB is openend it has a slightly different name.
I tried thunderbird* in your AHK script but it does not work. Is there an equivalent of thunderbird* for AHK that you know of?
I think
DutchPete wrote:Hi Lexikos, yes yours is probably a better solution for me because the kill process is an aggressive action. I tried your suggestion & it worked.
To close Thunderbird a sub-command is needed. Could you tell me how to do one?
I suppose that Process, close is similar to Taskkill although I'm not sure!

What names have the processes Thunderbird?
Everything is possible!
User avatar
empardopo
Posts: 336
Joined: 06 Oct 2013, 12:50
Location: Spain
Contact:

Re: Closing 5 programs with 1 keyboard shortcut

19 Feb 2015, 05:15

Other option you can test

Code: Select all

hotkey, ~k, killproc
return

killproc:
Process, Exist, thunderbird.exe
PID := ErrorLevel
If PID != 0
{
	WinGet, ID,ID, ahk_pid %PID%
	WinActivate,ahk_id %ID%
	Send, !{F4}
}
return

Greetings.
Everything is possible!
DutchPete
Posts: 98
Joined: 03 Feb 2015, 03:59

Re: Closing 5 programs with 1 keyboard shortcut

19 Feb 2015, 06:15

Empardopo, is your 2nd option a sub-command to the script suggested by Lexikos? I do want to keep his script because it does seem to be less aggressive. Can I just paste

Process, Exist, thunderbird.exe
PID := ErrorLevel
If PID != 0
{
WinGet, ID,ID, ahk_pid %PID%
WinActivate,ahk_id %ID%
Send, !{F4}
}
return

to the bottom of Lexikos's script? If so, what would it look like with the WinClose operator?

Just to give some further info about T/bird's processnames:
right now there is thunderbird.exe (which is always there), and there is thunderbird290C5155.tmp (which is different for each logon session).
lexikos
Posts: 6490
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Closing 5 programs with 1 keyboard shortcut

19 Feb 2015, 07:03

That is unlikely to be useful. Instead of closing the window directly, it sends Alt+F4 to close the window. It's also unnecessarily verbose:
  • Instead of retrieving the window ID of the top-most window belonging to that PID (the window identified by ahk_pid %PID%) and then activating by ID, it could just WinActivate ahk_pid %PID%.
  • Instead of picking one thunderbird.exe process and then the top-most window of that process by PID, it could just use ahk_exe thunderbird.exe. I don't think there's any advantage to retrieving the PID first in this case. The disadvantage is that if there are multiple thunderbird.exe processes, it will pick one and ignore any windows from other processes (even if the process it picked has no visible windows).
Does Thunderbird exit when you close its window? Is the problem just that the process name keeps changing? If so, just use the window title and/or class instead of the process name.
User avatar
empardopo
Posts: 336
Joined: 06 Oct 2013, 12:50
Location: Spain
Contact:

Re: Closing 5 programs with 1 keyboard shortcut

19 Feb 2015, 07:09

DutchPete wrote:Empardopo, is your 2nd option a sub-command to the script suggested by Lexikos? I do want to keep his script because it does seem to be less aggressive. Can I just paste

Process, Exist, thunderbird.exe
PID := ErrorLevel
If PID != 0
{
WinGet, ID,ID, ahk_pid %PID%
WinActivate,ahk_id %ID%
Send, !{F4}
}
return

to the bottom of Lexikos's script? If so, what would it look like with the WinClose operator?

Just to give some further info about T/bird's processnames:
right now there is thunderbird.exe (which is always there), and there is thunderbird290C5155.tmp (which is different for each logon session).
Try this

Code: Select all

hotkey, ~x, killproc
return

killproc:
WinGet, id, list,,, Program Manager
Loop, %id%
{
    this_id := id%A_Index%
    WinGetClass, this_class, ahk_id %this_id%	
    WinGetTitle, this_title, ahk_id %this_id%
	if this_class = MozillaWindowClass
		WinClose, %this_title%
}
return
In this code, I'm usign the class name MozillaWindowClass. I don't know the class name to Thunderbird.
Run a autohotkey script and pressing the right button of your mouse choose the Spy option. Then, put your mouse on the a Thunderbird window and you'll get the classname to use.

Greetings
Attachments
Spy.png
Spy.png (11.93 KiB) Viewed 3378 times
Everything is possible!
DutchPete
Posts: 98
Joined: 03 Feb 2015, 03:59

Re: Closing 5 programs with 1 keyboard shortcut

19 Feb 2015, 07:36

Empardopo thank you for this. To start with your last instruction: the classname is indeed MozillaWindowClass.

I am still not clear how to use your script:
* as a standalone, or
* as part of Lexikos's s script.

In either case, you write Killproc, but then use WinClose further down. Is it relevant to put in the word "killproc"?

Apologies for these questions, which to someone like you are probably stupid questions, but for a newbie to AHK like me nothing is obvious.
User avatar
empardopo
Posts: 336
Joined: 06 Oct 2013, 12:50
Location: Spain
Contact:

Re: Closing 5 programs with 1 keyboard shortcut

19 Feb 2015, 07:56

DutchPete wrote:Empardopo thank you for this. To start with your last instruction: the classname is indeed MozillaWindowClass.

I am still not clear how to use your script:
* as a standalone, or
* as part of Lexikos's s script.

In either case, you write Killproc, but then use WinClose further down. Is it relevant to put in the word "killproc"?

Apologies for these questions, which to someone like you are probably stupid questions, but for a newbie to AHK like me nothing is obvious.
I never have used the instructions that Lexixos showed to you. I'm sorry. Try and use the one that works best for you.

killproc is only a label. WinClose is an instruction of Autohotkey.

Greetings.
Everything is possible!
DutchPete
Posts: 98
Joined: 03 Feb 2015, 03:59

Re: Closing 5 programs with 1 keyboard shortcut

19 Feb 2015, 08:41

Empardopo, I understand your position. What I am trying to get my head round is if your script can be pasted to the end of someone else's script or if it is purely standalone.
If it can be pasted, does there need to be a bit of syntax to link the 2 or will your "bit" run no matter what?
DutchPete
Posts: 98
Joined: 03 Feb 2015, 03:59

Re: Closing 5 programs with 1 keyboard shortcut

19 Feb 2015, 08:48

@ Guest: no it won't because the problem with T/bird is that it is not just thunderbird.exe that needs to be stopped for the windows to close, there is another t/bird process too, but it has a different name each session.
User avatar
empardopo
Posts: 336
Joined: 06 Oct 2013, 12:50
Location: Spain
Contact:

Re: Closing 5 programs with 1 keyboard shortcut

19 Feb 2015, 09:09

DutchPete wrote:Empardopo, I understand your position. What I am trying to get my head round is if your script can be pasted to the end of someone else's script or if it is purely standalone.
If it can be pasted, does there need to be a bit of syntax to link the 2 or will your "bit" run no matter what?
I think there is no proble to use that

Code: Select all

; Create the group only once, with each app window on a separate line.
GroupAdd MultiClose, ahk_exe Notepad.exe
GroupAdd MultiClose, ahk_exe SciTE.exe

!q::
WinClose, ahk_group MultiClose  ; No comma between ahk_group and MultiClose.
; Note this closes the windows; it does not kill processes, so some apps
; might continue to run in the backgroud.
WinGet, id, list,,, Program Manager
Loop, %id%
{
    this_id := id%A_Index%
    WinGetClass, this_class, ahk_id %this_id%   
    WinGetTitle, this_title, ahk_id %this_id%
    if this_class = MozillaWindowClass
        WinClose, %this_title%
}
Return
Greetings.
Everything is possible!
DutchPete
Posts: 98
Joined: 03 Feb 2015, 03:59

Re: Closing 5 programs with 1 keyboard shortcut

19 Feb 2015, 09:44

Yep, that did it empardopo!! Many, many thanks.
User avatar
empardopo
Posts: 336
Joined: 06 Oct 2013, 12:50
Location: Spain
Contact:

Re: Closing 5 programs with 1 keyboard shortcut

19 Feb 2015, 09:52

DutchPete wrote:Yep, that did it empardopo!! Many, many thanks.
You are welcome! :D
Everything is possible!
lexikos
Posts: 6490
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Closing 5 programs with 1 keyboard shortcut

19 Feb 2015, 16:21

Once again, that is unnecessarily verbose.

If a MozillaClassWindow happens to have the same title as some other window, it could close the wrong window. ahk_id %this_id% identifies exactly one window, so rather than retrieving the title using the ID and then closing by title, it makes much more sense to close by ID (WinClose ahk_id %this_id%).

But since it's just closing every window of class MozillaWindowClass, you can "just use the window title and/or class instead of the process name" as I said before:

Code: Select all

GroupAdd MultiClose, ahk_class MozillaWindowClass
Be aware that using just the class (as in this or empardo's script) will also close Firefox and other programs based on the same technology.
enthused
Posts: 94
Joined: 27 Dec 2014, 03:28

Re: Closing 5 programs with 1 keyboard shortcut

19 Feb 2015, 23:09

would this work:

Code: Select all

SetTitleMatchMode, RegEx

; Create the group only once, with each app window on a separate line.
GroupAdd MultiClose, ahk_exe Notepad.exe
GroupAdd MultiClose, ahk_exe SciTE.exe
GroupAdd MultiClose, ahk_exe thunderbird(.*)

!q::
WinClose, ahk_group MultiClose  ; No comma between ahk_group and MultiClose.
; Note this closes the windows; it does not kill processes, so some apps
; might continue to run in the backgroud.
Return

Esc::ExitApp

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Getfree, Google Adsense [Bot], rediffusion, RinkaDink and 211 guests