Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Looking for fewest lines of code to reach goal

If you have a question or need help, this is the place to be.
Post Reply
burchis
Posts: 6
Joined: Sat Feb 01, 2014 5:12 pm

Looking for fewest lines of code to reach goal

Post by burchis »

I sometimes need two or three programs active at once. I dedicated three buttons on my remote, one for each of the three programs that I will use.

Button "A" opens program one
Button "B" opens program two
Button "C" opens program three

To switch focus between programs I want to press the corresponding button. If the program is NOT open it will open it, however if it is already open is switches focus to program.

I basically need some kind of "if then" conditional loop. So far I have used duplicate Find Window event but feel there must be a better way. I am probably missing something simple and hoping that someone can help out.

Thanks for any suggestions.
burchis
Posts: 6
Joined: Sat Feb 01, 2014 5:12 pm

Re: Looking for fewest lines of code to reach goal

Post by burchis »

I guess I will have to learn Python programming to achieve what I want to do. Are there any tutorials for first timers wanting to learn this language?
blaher
Experienced User
Posts: 487
Joined: Thu Nov 17, 2011 1:27 am

Re: Looking for fewest lines of code to reach goal

Post by blaher »

burchis wrote:So far I have used duplicate Find Window event but feel there must be a better way.
Sounds like a good way to do it, to me. If you post your .xml you might get some better suggestions on how to clean it up.
barnabas1969
Experienced User
Posts: 133
Joined: Sat Feb 04, 2012 1:42 am

Re: Looking for fewest lines of code to reach goal

Post by barnabas1969 »

Here's one solution. It requires setting up three different macros for each button.

Here's an example for Button A:

In the first macro, add the "Find a window" action. Un-check the box that says "stop macro if target is not found". Do not check the box that says "stop macro if target is found".
Then, add a Python Script action. In this action, add the following code:

Code: Select all

if eg.result == []:
    eg.TriggerEvent("StartProgButtonA")
else:
    eg.TriggerEvent("BringForegroundButtonA")
Now, create two more macros... one will be triggered by the event Main.StartProgButtonA, and the other will be triggered by the event Main.BringForegroundButtonA. Add actions to those macros to do what you want (bring it to the foreground, or start the program).

There is probably a more elegant way to do it. For example, the first part of the if statement could simply start the program instead of triggering an event. The else-part of the script could do the actions you want to bring it to the foreground. You'll have to search the documentation for those functions.
kkl
Experienced User
Posts: 317
Joined: Wed May 04, 2011 9:32 pm

Re: Looking for fewest lines of code to reach goal

Post by kkl »

Here's a thread on a loosely related topic.
Post Reply