StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Angel  
#1 Posted : Sunday, February 12, 2023 8:22:01 AM(UTC)
Angel

Rank: Newbie

Reputation:

Groups: Approved
Joined: 11/6/2022(UTC)
Posts: 3
Switzerland

Thanks: 2 times
Hello everyone,

I am brand new and the program has huge features.

I would like to use "StrokesPlus" to quit the programs on my Windows 10.
Because I programmed my mouse with a button to function ALT+W.

How do I do that ?

With the "Hot Keys" item, the "Exit" command is only for the program itself?

Thanks!

Greetings,

Angel
randomConstant  
#2 Posted : Sunday, February 12, 2023 1:10:26 PM(UTC)
randomConstant

Rank: Advanced Member

Reputation:

Groups: Translators, Approved
Joined: 7/17/2021(UTC)
Posts: 135

Thanks: 35 times
Was thanked: 18 time(s) in 15 post(s)
Welcome to S+ Mellow

I couldn't understand your exact requirements but here are a few ways to close programs.

To close a tab/window of an application, execute a gesture/hotkey with the script that will simulate pressing the application dependent tab close shortcut. e.g. for most applications:
Code:
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_W]);

will close an opened tab.

To (force?)close an application, you can try executing the good old Alt+F4 command. However, most applications can be closed by using the following action provided in S+
Code:
action.Window.SendClose();


If you need to close an application running in the background(app that you are not using currently), you can try to close it this way:
  1. Get a handle to that application using its title:
    Code:
    var wnd = sp.WindowsFromTitlePartial("Mozilla Firefox").First(); // Mozilla Firefox being an application title

  2. then close it gracefully with following commands:
    Code:
    wnd.Process.CloseMainWindow();
    wnd.Process.Close();

  3. or close it forcefully with following commands:
    Code:
    wnd.Process.Kill();


All of these ways to close apps are already discussed in this forum I think, that's how I got them IIRC.
Currently I'm using the following function to close an application(running in background):
Code:
function closeProgram(programTitle, forceKill = false){
try{
var wnd = sp.WindowsFromTitlePartial(programTitle).First();
if(forceKill){
    wnd.Process.Kill();
}else{
    wnd.Process.CloseMainWindow();
    wnd.Process.Close();
}
}catch{}
}

The above function definition can be placed in Global Actions->Load/Unload->Load->Script section. This way it will be accessible in all gestures and hotkeys and can be used in the following way:
Code:
closeProgram("Mozilla Firefox", true);


Oh and you can get the current(opened) application title using the following code snippet:
Code:
clip.SetText(String(action.Window.Title));

It will copy the title to your clipboard.

I hope this helps.

thanks 1 user thanked randomConstant for this useful post.
Angel on 2/12/2023(UTC)
Angel  
#3 Posted : Sunday, February 12, 2023 3:36:41 PM(UTC)
Angel

Rank: Newbie

Reputation:

Groups: Approved
Joined: 11/6/2022(UTC)
Posts: 3
Switzerland

Thanks: 2 times
Quote:


I hope this helps.



Thank you for your effort.

I want it to affect all programs.
And always only what is in the foreground.

But now I have seen that I already use this command with ALT+W to close windows in the programs,
like Goldwave etc.

Goldwave would then be terminated directly without first closing the open windows.

It should work in such a way that each individual window or tab is always closed first, step by step
and only then, at the very end, the program itself.
However, if the program has no windows and tabs like "Total Commander" it directly terminates the program.

Edited by user Sunday, February 12, 2023 4:32:07 PM(UTC)  | Reason: Not specified

randomConstant  
#4 Posted : Sunday, February 19, 2023 4:52:37 AM(UTC)
randomConstant

Rank: Advanced Member

Reputation:

Groups: Translators, Approved
Joined: 7/17/2021(UTC)
Posts: 135

Thanks: 35 times
Was thanked: 18 time(s) in 15 post(s)
hmmm so here is the requirement:
A script that closes an application, but if the application supports tabs or windows, then it closes those tabs first until they are all closed and closes itself at the end.
Please correct me if I'm wrong.

Rob would know better. But in my experience it is very application dependent. For example, Firefox browser by default closes its tab with CTRL+W combination. and on closing the last tab it automatically closes the browser (application) entirely.
But this behavior can be changed in its settings to keep the browser open when all tabs are closed. In which case pressing CTRL+W on last tab will close it but keep browser open with a new-tab page showing.

I personally use two different gestures for closing an application and its tabs/windows. Because as you pointed out, not all applications support tabs.
The only naive way I can think of to solve this with a single script(especially when the application itself does not close automatically after its all its tabs close) is to compare the application tab area for a certain color or check the application for its title(as title is tab/window dependent IIRC) and fire two different shortcuts for when the tabs are opened vs closed.

But there might be better ways to do it. Hopefully someone else shares it.
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.