How can I create a macro that automatically clicks all buttons that have the same View Id?

Ayano

Member
I want to make a loop that allows me to click as many buttons as I can see in my display.

It is the exact same button and there are multiple buttons to click and each button only needs to be clicked once.

The 'id of the button is the same but each button has a number for different, example:

com.app..:id/text$1
com.app..:id/text$2
com.app..:id/text$3

And it goes on like that.

I don't know how many buttons will appear in my display, may be 10,22,40 I don't know, however I have to press them all once each.

I had tried using contains excluding the final part of the number, however it kept pressing the buttons more than once and that is not what I want.

This loop should only trigger when there are buttons that have not been pressed once and it should stop when it has pressed all the ones it sees, and once it is finished I will do the other actions I want out of this loop.
 

hsurB

Well-known member
Read screen content. After using that action viev id is key in dictionary, right? (I am not sure)
Then you could run iterate dictionary/array action to check how many buttons you have to press.
Using if clause - if iterator's key contains com.app...:id/text* then set integer variable +1 (make sure you use wait before next action after that, otherwise loop might run too quickly)
That should be enough to find out how many keys you have on screen.

Then you can use that integer variable to run loop as many times as there is buttons. When setting ui interaction you could use another integer variable at the end of phrase as well. This one could be set to +1 each time loop runs

Edit. Notice that com.app..:id/text$175/abcjek for exemple will also add +1 in iterate action even though it might be different button that is not supposted to be clicked. You would have to check if thats the case.
Edit2. Now that I thought about it you could probably achieve it using iterate dictionary/array action alone - using if clause as above and ui interaction with iterator's key as view id since it would click only if key matches the pattern
 
Last edited:

Ayano

Member
Read screen content. After using that action viev id is key in dictionary, right? (I am not sure)
Then you could run iterate dictionary/array action to check how many buttons you have to press.
Using if clause - if iterator's key contains com.app...:id/text* then set integer variable +1 (make sure you use wait before next action after that, otherwise loop might run too quickly)
That should be enough to find out how many keys you have on screen.

Then you can use that integer variable to run loop as many times as there is buttons. When setting ui interaction you could use another integer variable at the end of phrase as well. This one could be set to +1 each time loop runs

Edit. Notice that com.app..:id/text$175/abcjek for exemple will also add +1 in iterate action even though it might be different button that is not supposted to be clicked. You would have to check if thats the case.
Edit2. Now that I thought about it you could probably achieve it using iterate dictionary/array action alone - using if clause as above and ui interaction with iterator's key as view id since it would click only if key matches the pattern
Later I'll try to do as you told me, I used the variable y-10 to make these clicks and Pecking the buttons in this way, do you think this new method of clicking buttons individually is better than the Y-10 series of clicks I'm currently using?
 

hsurB

Well-known member
If they are recognized by read screen content action this method above is better since it should be impossible to miss the button this way.
As long as there is a regex that will match only these buttons you want to click (pattern that we can use in if clause to compare current view id from dictionary and check if its the button we want to click).
I will attach simple macro that should show you the general idea of what I am talking about.
But if your dictionary has crazy long list of view ids it might be quicker using old method (probably unlikely)

Just make sure to change wait before to lower value. I used dictionary of 30 view ids for testing purposes so 1s was fine for me and add read screen at the start if you don't have it saved from another macro (I had)
 

Attachments

  • Screenshot_20240219_195035_MacroDroid.png
    Screenshot_20240219_195035_MacroDroid.png
    264.8 KB · Views: 17

Ayano

Member
If they are recognized by read screen content action this method above is better since it should be impossible to miss the button this way.
As long as there is a regex that will match only these buttons you want to click (pattern that we can use in if clause to compare current view id from dictionary and check if its the button we want to click).
I will attach simple macro that should show you the general idea of what I am talking about.
But if your dictionary has crazy long list of view ids it might be quicker using old method (probably unlikely)

Just make sure to change wait before to lower value. I used dictionary of 30 view ids for testing purposes so 1s was fine for me and add read screen at the start if you don't have it saved from another macro (I had)
Bro I'm trying now but I don't understand what key I've to select in the read screen content (this dictionary, add key or manually I don't know) then exclude or include ids without text and then exclude or include overlays?

view id is key in dictionary yes you are right, I need to set the view id that is the key
 

hsurB

Well-known member
This dictionary - include .. without text - exclude overlays to reduce size of dictionary
 

Ayano

Member
I
This dictionary - include .. without text - exclude overlays to reduce size of dictionar
This dictionary - include .. without text - exclude overlays to reduce size of dictionary
I created the variable in Read Screen Content and I called it Buttons Check. Now what I've to do? I don't know if I've to create another variable for the



This dictionary - include .. without text - exclude overlays to reduce size of dictionary
I created the variable in Read Screen Content and I called it Buttons Check. I setted the Buttons Check as variable of Iterate Dictionary Array. Now what I've to do? I don't know if I've to create another variable for the If loop? Tell me how to set the variable in click view Id loop, I don't know how to use magic text and {} I'm so sorry to bother you bro, I'm a truly new in using this app
 

hsurB

Well-known member
Create if clause with condition compare values (enter some random values for exemple 5=5 cause you cant use magic text iterator's key unless its inside iterate action anyway.
Move it inside the loop (iterate action) and change so it was the same as on the screenshot I posted above, once its inside the loop you can reconfigure compare values in if clause and use magic texts for iterator's key (select string there)
 

Ayano

Member
Create if clause with condition compare values (enter some random values for exemple 5=5 cause you cant use magic text iterator's key unless its inside iterate action anyway.
Move it inside the loop (iterate action) and change so it was the same as on the screenshot I posted above, once its inside the loop you can reconfigure compare values in if clause (select string there)
Compare values type boolean or integer, string?
 

Ayano

Member
Iv
Create if clause with condition compare values (enter some random values for exemple 5=5 cause you cant use magic text iterator's key unless its inside iterate action anyway.
Move it inside the loop (iterate action) and change so it was the same as on the screenshot I posted above, once its inside the loop you can reconfigure compare values in if clause and use magic texts for iterator's key (select string there)

I've to enable regular expression matching?
 

Ayano

Member
bro it works, however when I change pages it becomes slow to click the buttons and I have to restart the macro.

I think it's due to the fact that there are too many sentence, let's put 100 sentences by section so I easily get over 1000 and the dictionary becomes slower and few times it didn't click some buttons, maybe because they were too small I don't know.

So I would like if possible that when it doesn't see more buttons it does a 20 seconds wait and after that it clears the dictionary and when I scroll to change page and new buttons will appear it automatically restarts this loop so on until it sees the view Id next chapter
 

hsurB

Well-known member
Its really hard for me to help more as I don't have access to the dictionary its supposted to work on. I don't know in what scenarios you used the macro etc.

Its possible that you triggered macro again before it finished runing iteration and thats why it became slow later or started missing buttons/clicking the same again. I am not sure what value you used in wait before next action.
Also if these buttons appear next to each other in dictionary and once their view ids don't appear anymore there is no chance there might be one few keys later there is probably a chance to implement it to stop iteration as soon as it stops detecting these view ids (cause we know they won't appear again - I am not sure if thats the case)

I highly recommend checking macrodroid's wiki and having fun with app to learn it to creating these macros alone later
 

Ayano

Member
I
Its really hard for me to help more as I don't have access to the dictionary its supposted to work on. I don't know in what scenarios you used the macro etc.

Its possible that you triggered macro again before it finished runing iteration and thats why it became slow later or started missing buttons/clicking the same again. I am not sure what value you used in wait before next action.
Also if these buttons appear next to each other in dictionary and once their view ids don't appear anymore there is no chance there might be one few keys later there is probably a chance to implement it to stop iteration as soon as it stops detecting these view ids (cause we know they won't appear again - I am not sure if thats the case)

I highly recommend checking macrodroid's wiki and having fun with app to learn it to creating these macros alone later
I want to create a loop to translate these phrases by pressing all of these buttons.

Maybe I clicked before the end of the macro I don't know.

I've set up a Wait of 25ms.

After a phrase us translated at 99% That sentence will no longer be there is very unlikely.
 

Attachments

  • Screenshot_20240219_222930.png
    Screenshot_20240219_222930.png
    1.3 MB · Views: 12

hsurB

Well-known member
After runing read screen content action does it save entire text into dictionary or you have to scroll down to save next part?
 

Ayano

Member
After runing read screen content action does it save entire text into dictionary or you have to scroll down to save next part?
after I start the macro in my dictionary for the most part there are empty entries with the view id and empty values in the key and in some there is the view id with the phrases.

I am only interested in clicking the buttons, not interested in storing the phrases in the dictionary.
 

hsurB

Well-known member
Go edit your macro and at the end (outside of loop) add action pop up message with: 'Iteration finished' (or whatever)

Increase wait before next action from 25ms to 100ms, go to that screen and run macro again till it shows pop up message.
During this time don't click anything, don't scroll until you will see the pop up.
Describe what happened.
 

Ayano

Member
Go edit your macro and at the end (outside of loop) add action pop up message with: 'Iteration finished' (or whatever)

Increase wait before next action from 25ms to 100ms, go to that screen and run macro again till it shows pop up message.
During this time don't click anything, don't scroll until you will see the pop up.
Describe what happened.
The result is:

It took a long time to load the macro and finally clicked all the buttons.

There were 100 sentences however there are 1000 entries in the dictionary, there are things that should not have been there.

Example:

I only want

com.... id/banana

There are:

a few com.androidthingsid

a lot of com...id/bananacherry empty

a lot of com.. id/bananamango empty

a lot of com..id/bananamango with phrases

So there are a lot of useless things similar to my bananas That have not been filtered.

I would only like for example idbananas.

Not bananasmangos.

These things take up space unnecessarily in the dictionary and triple the elements and everything gets slower so I need to filter the View id better so that it doesn't accept things that are not only banana id, it has to eliminate ids that contain ALSO banana, for example babanacherry.

I guess instead of contains it needs an exact match.
 
Top