Page 1 of 1

Detect current opened window

Posted: 25 Aug 2017 07:21
by xpdev
Hi

there is a way to detect (in a condition) what window in opened ?

For example if wi-fi setting is opened.

Or a trigger to detect when a window is closed from user ?
i can detect wihit a trigger if a window is opened but not if it is closed from user.

Thank you

Re: Detect current opened window

Posted: 25 Aug 2017 10:31
by Desmanto
You want a condition behave like a UI event waiting for some text to disappear? There is no trigger Event UI to detect closed windows. There is also no condition related to UI, but you can query it using action Control UI + condition to loop it. You need to tell us what exactly you wanna achieve.

Here I assume you have fixed window text and you wanna do something if that windows is closed. Using loop with sleep, you can query the windows

Action 1 : Control UI
text = getTextInActiveWindow()

Use expression to detect if your current window contain some text that is unique. Example current window has "Wi-Fi settings"

Condition : Expression
contains(text, "Wi-Fi settings")

Action True : Sleep 1 Seconds, then connect back to Action 1 (Control UI)
Action False : Whatever the action you wanna do after current windows closed.

Starting from Action 1, the flow will query current window's text and find the unique text. If it is found, then it will sleep and check back after 1 second (you can make it longer or shorter). As long as the text Wi-Fi settings is still detected on current windows, the flow will loop infinitely (until emergency stop). After the text is not detected anymore, the loop breaks and continues the flow.

You have to make sure Action 1 starts exactly at the windows that you want. So most likely the trigger will be UI Event, Window opened : wi-fi setting. You can use debug dialog to check the content of the text, to search for the unique keyword you can use. Or you can just match the whole text if you want to be strict.

If you use sleep 1 second, the loop contains 3 elements, so there will be approx 3 elements execution per second (at my phone, that 3 elements takes about 1,1 seconds per loop). If that window can be opened more than a minute, make sure you set the emergency stop for that flow set to 180 above. In case you make the sleep shorter, example 500 ms, that means 2 loops (6 elements per second), you should have emergency stop set at 6 x 60 = 360

You can also make the loop more efficient by implementig sleep into control UI script. Remove the sleep action and add sleep(1000); before the getText.

Re: Detect current opened window

Posted: 25 Aug 2017 11:20
by xpdev
Thank you for you answer

first problem

i don't know how use

Action 1 : Control UI
text = getTextInActiveWindow()

Automagic tells me that getTextInActiveWindow() is unknown

thank you

Re: Detect current opened window

Posted: 25 Aug 2017 11:44
by Desmanto
What version of Automagic do you use? 1.33.0 right?

Variables and functions are case-sensitive, make sure you type it correctly. And that function only available at Control UI, not Script. To make sure you get it right, just tap function at Control UI, search "window", you should see the choice and choose it. All function can be chosen this way.

Re: Detect current opened window

Posted: 25 Aug 2017 11:56
by xpdev
Ok, i have found it, mi foult.

Thank you, now i can use it.

Re: Detect current opened window

Posted: 26 Aug 2017 15:00
by Desmanto
I am currently learning Python (to integrate Automagic to EventGhost). Just realize, i never use While() to loop.
Turns out we can even make that 3 elements more efficient by just using while()
Scratch that condition expression and action sleep. We only need Action Control UI.

This is the script for Action Control UI

Code: Select all

while (contains(getTextInActiveWindow(), "UI tester"))
  sleep(1000);
No need extra variable, no need extra expression checking. Perfomance for single loop (single element) is 1,03 seconds (compared to 1,10 seconds when split to 3 elements).
You most likely don't need to change the emergency stop. (or maybe only need to increase it a bit to 80)

Re: Detect current opened window

Posted: 23 Feb 2019 19:58
by jmckeejr
The only text I'm able to find in the window I want to monitor is the current time (this is for a notification panel replacement as my radio in truck does not have notification panel by default, instead has shortcuts for radio, nav, video, etc). I have a widget on status bar which will open the flow and show Power Shade, but I need it to revert to normal behaviour when Power Shade window closes, else I can't use the shortcuts built into OS. Should this work?
While (contains(getTextInActiveWindow(), "{getDate(), dateformat, HH:mm}"))
Sleep(1000);

It's not working for me, but I am not sure I am doing it correctly.

Re: Detect current opened window

Posted: 24 Feb 2019 17:00
by Desmanto
The problem is you don't know if getTextInActiveWindow() will catch the time or maybe the time is not using HH:mm format when stored. You need to try to log the getTextInActiveWindow() content to see the result when the power shade window open and closed.

BTW, I still don't get what you need. Maybe there is alternative method to do it. Trigger UI event maybe can catch something too. You can try to check the recent event in the trigger

Re: Detect current opened window

Posted: 14 Mar 2019 04:56
by hgtyu654
Great Information..This well be very useful..

Re: Detect current opened window

Posted: 14 Mar 2019 07:48
by jmckeejr
Desmanto wrote:The problem is you don't know if getTextInActiveWindow() will catch the time or maybe the time is not using HH:mm format when stored. You need to try to log the getTextInActiveWindow() content to see the result when the power shade window open and closed.

BTW, I still don't get what you need. Maybe there is alternative method to do it. Trigger UI event maybe can catch something too. You can try to check the recent event in the trigger
Found different app does what I wanted