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.
Closing 5 programs with 1 keyboard shortcut Topic is solved
Closing 5 programs with 1 keyboard shortcut
Last edited by DutchPete on 18 Feb 2015, 09:08, edited 1 time in total.
Re: Closing 5 programs with 1 keyboard shortcut
Perhaps, this code can be useful for you
Greetings.
Code: Select all
Hotkey, ~k, killProc
return
killProc:
Process, close, notepad.exe
Process, close, thundebird.exe
Process, close, evernote.exe
return
Everything is possible!
Re: Closing 5 programs with 1 keyboard shortcut
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?
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?
Re: Closing 5 programs with 1 keyboard shortcut
I would kill processes only as a last resort.
If you know the window title and need a process ID, you can use the PID sub-command of WinGet.
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
Re: Closing 5 programs with 1 keyboard shortcut
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?
To close Thunderbird a sub-command is needed. Could you tell me how to do one?
Re: Closing 5 programs with 1 keyboard shortcut
I thinkDutchPete 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 suppose that Process, close is similar to Taskkill although I'm not sure!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?
What names have the processes Thunderbird?
Everything is possible!
Re: Closing 5 programs with 1 keyboard shortcut
Other option you can test
Greetings.
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!
Re: Closing 5 programs with 1 keyboard shortcut
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).
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).
Re: Closing 5 programs with 1 keyboard shortcut
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).
Re: Closing 5 programs with 1 keyboard shortcut
Try thisDutchPete 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).
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
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 (11.93 KiB) Viewed 7388 times
Everything is possible!
Re: Closing 5 programs with 1 keyboard shortcut
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 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.
Re: Closing 5 programs with 1 keyboard shortcut
I never have used the instructions that Lexixos showed to you. I'm sorry. Try and use the one that works best for you.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.
killproc is only a label. WinClose is an instruction of Autohotkey.
Greetings.
Everything is possible!
Re: Closing 5 programs with 1 keyboard shortcut
Doesn't this technique work for you http://ahkscript.org/boards/viewtopic.p ... 057#p37057 just replace palemoon.exe with thunderbird.exe
Re: Closing 5 programs with 1 keyboard shortcut
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?
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?
Re: Closing 5 programs with 1 keyboard shortcut
@ 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.
Re: Closing 5 programs with 1 keyboard shortcut
I think there is no proble to use thatDutchPete 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?
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
Everything is possible!
Re: Closing 5 programs with 1 keyboard shortcut
Yep, that did it empardopo!! Many, many thanks.
Re: Closing 5 programs with 1 keyboard shortcut
You are welcome!DutchPete wrote:Yep, that did it empardopo!! Many, many thanks.
Everything is possible!
Re: Closing 5 programs with 1 keyboard shortcut Topic is solved
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:
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.
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
Re: Closing 5 programs with 1 keyboard shortcut
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