Help with Singleinstance

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
mikeyww
Posts: 26890
Joined: 09 Sep 2014, 18:38

Re: Help with Singleinstance

Post by mikeyww » 02 Nov 2020, 07:01

Excellent! I am not connected to the foundation but still thank you for your generosity!
elad770
Posts: 82
Joined: 30 Oct 2020, 16:21

Re: Help with Singleinstance

Post by elad770 » 02 Nov 2020, 09:39

Thank you so much.

So, I have encountered another tiny problem and I hope you don't think I'm being ridiculous.

Every time the action is taking place there's a TIK sound that the script or the computer generates.

I've made a short clip to demonstrate this. I used notepad. As you can see and hear there's a Tik sound every time the previous window is closed

When a recording is made with other programs (like mp3 recorder) this sound is actually heard and overall is annoying.

Can you check this and see why this is happening? Here's the short clip

https://youtu.be/ANd3Ub-TNq8
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: Help with Singleinstance

Post by boiler » 02 Nov 2020, 09:44

Remove this line from the code:

Code: Select all

SoundBeep, 1500, 30
elad770
Posts: 82
Joined: 30 Oct 2020, 16:21

Re: Help with Singleinstance

Post by elad770 » 02 Nov 2020, 10:08

Incredible!

Thank you so much.

I have another challenge. I hope you'll be able to provide some insights

https://www.autohotkey.com/boards/viewtopic.php?f=76&t=82789
ndiaz
Posts: 73
Joined: 10 Jan 2017, 17:05
Contact:

Re: Help with Singleinstance

Post by ndiaz » 11 Feb 2023, 09:55

Thank you all for this thread! I've just used the script provided by @mikeyww to successfully close an unwanted second instance of a program I use every day.

I have a question. If I wanted the script to abort/prevent the opening of the second (new) instance instead of closing the one that's already open, would it be a matter of replacing the variable in the WinClose line or would a different script altogether be better for that?

While this script is wonderful for some programs such as Notepad that open and close very quickly, I'm dealing with a sluggish program that takes a while to open and close, so it would be better simply stop the second instance from running at all.

Thank you in advance!
User avatar
mikeyww
Posts: 26890
Joined: 09 Sep 2014, 18:38

Re: Help with Singleinstance

Post by mikeyww » 11 Feb 2023, 10:09

A possible approach: when a window is created, use WinGet to see whether more than one window exists for the window's process name. If so, close the older window, or the newer one. WinGet will get the window handles for matching windows, from top to bottom.
Post Reply

Return to “Ask for Help (v1)”