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.

Programming macros to handle different situations

If you have a question or need help, this is the place to be.
Post Reply
ijourneaux
Experienced User
Posts: 102
Joined: Wed Feb 17, 2010 2:20 am

Programming macros to handle different situations

Post by ijourneaux »

I would like to create a macro script that would do the following

1. If application X is running close application X
2. If application Y is running then bring application Y to foreground
3. If application Y is not running then start application Y (and bring it to the foreground).

MY first attempt at the script only handles the easiest case. X is already running and Y is not running. Unfortunately if X is not running when I click on the macro button, the script closes (the close command closes the topmost window) the next available window (which is not good) and tries to start Y.

Any tips?
kalia
Experienced User
Posts: 109
Joined: Wed Aug 12, 2009 1:10 am

Re: Programming macros to handle different situations

Post by kalia »

I am no programmer, but I think logically your Python script should look something like this:

If Find Window of X:
....Bring Window of X to Front
....Close X

If Find Window of Y:
....Bring Window of Y to Front
Else:
....Start Y
....Bring Window of Y to Front

Just putting my two cents in as I have been playing with some IF statements in Python this past week.
ijourneaux
Experienced User
Posts: 102
Joined: Wed Feb 17, 2010 2:20 am

Re: Programming macros to handle different situations

Post by ijourneaux »

kalia wrote:I am no programmer, but I think logically your Python script should look something like this:

If Find Window of X:
....Bring Window of X to Front
....Close X

If Find Window of Y:
....Bring Window of Y to Front
Else:
....Start Y
....Bring Window of Y to Front

Just putting my two cents in as I have been playing with some IF statements in Python this past week.

I was originally looking for an approach that would use the plug ins and hadn't even thought of what you suggested. It should work. I will look at it later tonight.
ijourneaux
Experienced User
Posts: 102
Joined: Wed Feb 17, 2010 2:20 am

Re: Programming macros to handle different situations

Post by ijourneaux »

I was able to accomplish what I needed to do using the Jump command. A python solution would ahve been more elegant but not necessary at this point (atleast until I need something more complicated.

Thanks for the comment though searching for how to do this using python exposed me to the jump command.
User avatar
jinxdone
Plugin Developer
Posts: 443
Joined: Tue Jan 02, 2007 4:08 pm

Re: Programming macros to handle different situations

Post by jinxdone »

Just as a tip for the future, if you want to make as simple of a python script for this kind of scripting logic as possible all you really need is the if..then..else statements and make them execute some eg.TriggerEvent calls.

Then you can use those new events to trigger macros as usual to run the actual actions you want for each possible outcome.
ijourneaux
Experienced User
Posts: 102
Joined: Wed Feb 17, 2010 2:20 am

Re: Programming macros to handle different situations

Post by ijourneaux »

I understand the if-then-else structure. What I had difficulty with was the test for a window/application existance. A search for python calls to accomplish this wasn't fruitful. If you could point me to a reference, I can probably take it from there.
Post Reply