It is currently September 29th, 2024, 3:28 pm

Preventing multiple instances of apps opening

General topics related to Rainmeter.
SkadefrQen
Posts: 2
Joined: March 17th, 2014, 9:50 am

Preventing multiple instances of apps opening

Post by SkadefrQen »

I am new to Rainmeter and I already love it!
A big thank you to the developer and supporters from me :)

Would there be any way to make a counter or set a flag?
To make it, so when I click on a button to open the app, it will check if the app is already running and minimize or maximize the app and not open multiple instances?

I did read "What Rainmeter is not..." and although looking through 15 pages, I am sorry if I missed already posted threads on the subject.
User avatar
jsmorley
Developer
Posts: 22790
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Preventing multiple instances of apps opening

Post by jsmorley »

Something like this should partially address the question. It won't "minimize" or "maximize" the app, which is just outside the control of Rainmeter, but will keep it from running multiple times:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

[MeasureRunNotepad]
Measure=Plugin
Plugin=Process
ProcessName=Notepad.exe
Disabled=1
UpdateDivider=-1
IfBelowValue=1
IfBelowAction=["Notepad.exe"]

[MeterNotepad]
Meter=String
FontSize=12
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Notepad
LeftMouseUpAction=[!EnableMeasure MeasureRunNotepad][!UpdateMeasure MeasureRunNotepad]
What happens when you execute an app that is already running is just not something that Rainmeter can in any way control. It is entirely up to the app. Some, like Notepad, will open a second instance. Some, like Calculator, will "restore" and give focus to the existing instance. Others, like Chrome, will open a new tab in the existing instance if the command has a parameter to open a page, or will open a whole new instance if not. Rainmeter just can't know or control the behavior. It's baked into the application itself.

You would need some external utility, maybe something in AutoIt, that could be passed the name of an application, and if it is already running "restore" or "minimize" the window based on its current state, or run the app if not. Not something that Rainmeter can do natively. Even then, there are some apps, Calculator and Windows Media Player for instance, that just won't obey commands from other apps to minimize or restore. Not sure there is an entirely reliable solution.
SkadefrQen
Posts: 2
Joined: March 17th, 2014, 9:50 am

Re: Preventing multiple instances of apps opening

Post by SkadefrQen »

I need to say thank you, and btw congrats on your 10.000 post count. You really are very helpful, with quick replies, sir :)

I see. Lots of variables in play, especially with 3rd party apps.
I know AutoIt to be too static for these dynamic and random user circumstances, and my request does not apply to all sorts of applications, only the browser (Waterfox) and native Windows apps.

People will always try to pretend, they are in control. And this raimmeter app should- according to some posted images of desktop I've seen - control the very universe itself ;)
So, before starting to go deep into any new stuff, I think it's important to learn about it's technical limitations, in order to not hit the wall at some point later on.
I will need to have a look into .lua to see what you just did there and see, if Rainmeter is worth the effort.