My previous reply disappear !!!! Wonder what happen, I remember have replied to you several days ago. Fortunately it is copied to my buffer clipboard, so I can still retrieve it before got deleted.Econdoc wrote:I did as you suggested and checked the states when the button was on. You, of course, were correct. The “ON” condition was true.
I cannot begin to tell you how many hours I spent trying to figure out what was going on. The fact that isChecked(“OFF”) never correctly indicates the state of a button is not only confusing, but downright nasty. I believe that all users should be advised and warned not to use those conditions. Unless told otherwise, who could possible know that the isChecked() condition never returns a correct result unless the button is ON.
Thanks for your patient help. I am getting very, very discouraged with Automagic.
========================================Actually, I also just realize yesterday when replying the post, that the true only returned when checking the ON, not the OFF. I don't know exactly your usage case, that's why can't give the direct suggestion.
No, Automagic should not limit any of the script function. This is the problem with most cases, but not at all cases. At several app/phone, the toggle label probably reversed. So if the state is off, it is possible the label stated ON (means to turn it on). It is also possible that the label doesn't change at all. So it is up to the user who determine which one is the correct one.
Those hours were not wasted, you have learnt something valuable first-hand. I also have spent a lot of time in the Control UI and scripting; sometimes just doing multiple series of tests just to confirm my finding or to use it in the flow I am building right now. The recent one, when I am typing this post is how to find the current timezone, I need to add it back to the time to get the time based on our current timezone. There is no direct function to do it. There is java function, but Automagic always crash when parsing it; I don't how to extract out the timezone. I also have spent probably hours (including from several weeks ago), trying to figure it out. I don't just simply find it at once, but thru multiple tests spread across so many chances. So I try, error, fail, try again, fail, digress. Try again in another chance and so on. And I just get it about an hour ago, and turns out just a simple nested getDate().
So as long as we don't give up and progress along a sane path, we eventually figure it out. Just remember to take a rest from time to time when you hit the wall. Sometimes forcing thru it won't get you anything, as your mind probably saturated already. Have fun, doing something else, let the problem sink and return back when you almost forget it already. Sometimes I just figured it out when doing something else and remember the script and get the idea to solve it out of nowhere. I don't keep thinking about it, it just come to my mind, kinda like inspiration. (of course, I have done my series of tests and fail before)
Do you have another button with "ON" label in the same window? Because using isChecked(pattern) will always retrieve the first "ON" label started from top-left corner. If there is, that button is the one get checked, no the airplane button. And you have to brace the if() when it has additional else, even thought the if() only has 1 line of script. The proper one should beEcondoc wrote:I have been doing more testing and finding more anomalies. I am playing with Oreo 8.1 (LineageOS) and that may explain some of the very strange results that I am getting. Here is the latest:
Airplane mode is OFF. The button is showing that airplane mode is disabled.
Checking the Airplane mode button with the following code returns incorrect results. Here is the code:
If (isChecked(“ON”))
Buttonon=true
Else
Buttonon=false;
Buttonon is always true! The slider button is clearly off.
It is impossible to correctly determine the state of airplane mode if isChecked(“ON”) does not correctly report it. Is this an Oreo issue?
Code: Select all
If (isChecked(“ON”))
{
Buttonon=true;
}
else
{
Buttonon=false;
}
Code: Select all
Buttonon = if(isChecked("ON") true else false;
Code: Select all
Buttonon = isChecked("ON");