Page 1 of 2

If scripting

Posted: 20 Sep 2017 19:48
by TheUnknownBuffalo
Hi all

I'm trying my hand at some scripting, and wondered how I accomplish this?


if (gettext="Click me")
{
start flow execution "close app"
}
else
{
carry on with workflow
}

Re: If scripting

Posted: 20 Sep 2017 20:13
by yogi108
TheUnknownBuffalo wrote:Hi all

I'm trying my hand at some scripting, and wondered how I accomplish this?


if (gettext="Click me")
{
start flow execution "close app"
}
else
{
carry on with workflow
}
Hi,
For comparison you have to use ==, otherwise variable gettext becomes 'Click me'.

You can use your construction with if in a condition expression.

If(var=="Click me")
{
return true;
} else
{
return false;
}

In the yes branch make action close flow, in the no branch continue flow.

Regards

Re: If scripting

Posted: 20 Sep 2017 20:33
by TheUnknownBuffalo
I've now done this, does that look ok?

title=getText(639, 306);
If(title=="Click me");
{
return true;
} else
{
return false;
}


Automagic is showing:

[expression expected[66], unknown function name 'getText'[7-14], unknown function name 'If'[26-28]]

Re: If scripting

Posted: 21 Sep 2017 02:07
by Desmanto
getText() is not available at Script action. It is part of the Control UI script, so you have to use Action Control UI, not Script.
It is easier to use Overlay control to get the script. Better choose getTextById() if it exist from the choice. Then assign value to certain variable if it is true, and evaluate that variable using expression.

Example I just use automagic default name text

Code: Select all

if(getTextById("ch.gridvision.ppam.androidautomagic:id/name_edit_text") == "this is the default name of the action")
  carry = "on"
Add new expression after this control UI

Code: Select all

carry == "on"
True branch execute flow "close app"
False branch continue with whatever your previous workflow.

==============================

There is more advanced way to make this control UI (or script) to behave like expression, where it can split to 2 branch, using exception handling. So you don't need extra expression element. Or even make a single expression can evaluate to 3 possible outcome (instead of 2 only), true, false and exception. But that will kinda confusing when you look at your flow, and need extra explanation.

Re: If scripting

Posted: 21 Sep 2017 15:49
by TheUnknownBuffalo
I've got the gettextbyid and put it inside a controlui command

When certain text is displayed, I want it to execute another workflow

Re: If scripting

Posted: 21 Sep 2017 16:36
by TheUnknownBuffalo
Sorry for posting a short reply, I'm getting frustrated with myself, I know the logic, but can't convert that into a simple workflow lol

Re: If scripting

Posted: 21 Sep 2017 18:13
by TheUnknownBuffalo
I've been looking at my app in detail, and I can't put the gettextbyid in a flow, but as a trigger - can that be done?

Re: If scripting

Posted: 22 Sep 2017 01:52
by Desmanto
If I understand you correctly, you want to detect certain text in your app and execute the flow according to it? If yes, you must use Trigger UI Event, not Control UI.

One of my flowception do the same as well. It is to create expression which check for multiple triggers. I use UI event, filter to Automagic package name, Window opened, contains text "Select Triggers". When the window appears, my flow triggerred and show the widget button so I can press it to do create the expression. But there are two places in automagic which can have this text "Select Triggers" : one when adding new triggers, and the other one when editing current multiple triggers (this is the one I need). So I have to use Control UI to check if the second one alertTitle component exist. If yes, continue the flow; if no, stop there. Everytime I open both window, the flow triggerred, but only the second one will continue to show up the widget.

In your case, use the same UI event, filter to your app, Window opened. Use some text that is unique to that window. Or just leave that UI event opened, go to your app, open until the desired window, back to automagic and select that from Recent Events. In most cases, you don't need Control UI anymore. But if you face the same as mine, where the text appear in two place, then use additional Control UI to separate them.

Re: If scripting

Posted: 22 Sep 2017 07:13
by TheUnknownBuffalo
Unfortunately the text doesn't show as an event, so I can only use gettextbyid which is a pain :(

Re: If scripting

Posted: 22 Sep 2017 08:04
by Desmanto
TheUnknownBuffalo wrote:Unfortunately the text doesn't show as an event, so I can only use gettextbyid which is a pain :(
Change the UI event matches text to matches glob, and put *
It will matches every opened window in the app, so you have to filter using Control UI.
And don't use getText, but use existsElementById()