Detect current opened window
Moderator: Martin
Detect current opened window
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
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
Xiaomi MI 6
Rom Miui 10 EU STABLE
Rom Miui 10 EU STABLE
Re: Detect current opened window
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.
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.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Re: Detect current opened window
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
first problem
i don't know how use
Action 1 : Control UI
text = getTextInActiveWindow()
Automagic tells me that getTextInActiveWindow() is unknown
thank you
Xiaomi MI 6
Rom Miui 10 EU STABLE
Rom Miui 10 EU STABLE
Re: Detect current opened window
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.
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.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Re: Detect current opened window
Ok, i have found it, mi foult.
Thank you, now i can use it.
Thank you, now i can use it.
Xiaomi MI 6
Rom Miui 10 EU STABLE
Rom Miui 10 EU STABLE
Re: Detect current opened window
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
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)
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);
You most likely don't need to change the emergency stop. (or maybe only need to increase it a bit to 80)
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Re: Detect current opened window
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.
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
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
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
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Re: Detect current opened window
Great Information..This well be very useful..
Re: Detect current opened window
Found different app does what I wantedDesmanto 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