Page 1 of 1

gui that allows cmdline executions

Posted: 22 Oct 2020, 13:31
by BGM
My app is a commandline application with a GUI for its settings.

If you run the program without parameters it opens the GUI.
But if you run it with parameters, it runs the script without any GUI.

I have the script set to look for commandline parameters and if there are none, it will launch the GUI, if not, it will run it's sequence and then exit.

Well, that's what is supposed to happen.

What happens is, if the GUI is open, the second instance kills the first one.
If I turn #SingleInstance to off, then it lets the user open multiple options GUIs which I don't want.

Here's what I want:
1. Be able to run the GUI instance and commandline instances at the same time.
2. Not be able to open two GUIs.
3. Have the commandline instances to not kill the GUI instance.

Maybe if there was a way to detect a previously running instance of the application?

Re: gui that allows cmdline executions

Posted: 22 Oct 2020, 13:51
by BGM
Hmmm, I think I might have figured it out (always happens after I post).

I only need to kill the second instance of the gui.
If I do this, then it leaves any first instance alone, but if I call it with parameters, it allows the hidden instance to run.

Code: Select all

#singeinstance, off
if not %0%
{
	winget, windowcount,Count,%appname%
	if(windowcount > 1){
		exitapp
	}
	gosub, MAINWINDOW

}else{
	loop %0%
	givenpath := %a_index%
	{
		loop %givenpath%, 1
		{
			msgbox, %a_loopfilelongpath%
		}
	}
	exitapp	;end the program now
}

Re: gui that allows cmdline executions

Posted: 22 Oct 2020, 16:58
by mikeyww
I think that's the idea. I have some GUI setups where I give the GUI a particular name (window title) so that I can easily have a separate script identify it. That approach can be a helpful adjunct.

Re: gui that allows cmdline executions

Posted: 29 Oct 2020, 09:53
by BGM
Funny, this code works on my own computer, but doesn't work on others. I tried it on another computer and it keeps the gui from launching the first time, not the second.

Re: gui that allows cmdline executions

Posted: 29 Oct 2020, 10:00
by mikeyww
You can debug it by breaking it down into steps. Eliminate the initial directive. Have the script display the command line, so that you can verify it. Display the window count, so that you can verify that. Etc.