Copy Text from a file.txt Line by Line on every run

adeelshezad230

New member
Hi Mates
i want to copy text from a file and paste into an app text field LINE BY LINE everytime macro run should go for next line text
forexample : i am searching my desired numbers in a search field but its a list of numbers cannot put one by one
i can make mostly macros but this one is confusing me need experts help Thanks
here is my text file example
 

Attachments

  • Untitled.png
    Untitled.png
    6.5 KB · Views: 15

RSF

Well-known member
Using a shell script to read the nth record from a file (using e.g. sed) might work. It may not be the most efficient scheme, but as long as you have a limited number of records, that could work.
 

Jacob L

Moderator (Lawsonator)
Give this a try. You may need to modify it for your needs:
 

Attachments

  • Copy_line_by_line.macro
    6.3 KB · Views: 100

RSF

Well-known member
Give this a try. You may need to modify it for your needs:
How can one get the contents of a file into a variable, for this script to work, though? Seems like everything I've tried in a shell script (cat, sed, etc.) says "Permission Denied". I've tried internal storage, and an SD card, but neither works -- even folders that MacroDroid successfully reads and writes for imports & exports.
 

Jacob L

Moderator (Lawsonator)
The command is usually cat /storage/emulated/0/text.txt

you then tick save result into string variable
 

RSF

Well-known member
May just be my phone, or Android version (11), but there's a permissions constraint with reading from files, even ones that I just created with MacroDroid's "Write to File" action.

It looks like my Android version only allows MacroDroid to read "media" files. Even if I just created a text file -- with MacroDroid itself, using Write-to-File actions -- I get
cat: /storage/emulated/0/MacroDroid/test.txt: Permission denied​
when using cat on the file in a shell action. But if I rename the same file to text.jpg, I'm able to cat it in a shell action without problems...

Looking at permission settings for MacroDroid, Android presents only "Allow access to media only" or "Deny" ...

rJv6AbA9OAHpXV9l_BkgXbWvaQZsrOj1E-JG7hpBcC1brySiYI5fvSqpsC2KeHDXyALxrb1275Co31eRnHPwLdekIkQzIhwMYgkfUmg2QihaMIWvRWofkDFjBZv_kfCD9hBZco8eYzDEhskk6rT2d5YU6MBYdlLfc2AuqKbQ-gpNw2bGJq59ofo_3u9T0cOxTRrenu6abEyeBRYzE1j4HX-gxEg-D1YyuZzNhs688LM6GkV6kgbV4GE35KsKGqowuOv_kDi-AYmCxnARg_AGF1g0KsibuhvKunD-jIZLGI0DjDR6tBlroiGmgsUtUNvWFao-to-eJBlLSZ6WC3yslv7nI9rmlbcKIkDFfxce8iH9U91qbmCm2ze7BJrMB2tCTQReYg1unn6ftT1ZBon_9EmEuwHUFcEZBYowhzOai_EwOOxsyl_xK9Vgjl-QKNWUYU5UQATeba7HS6SsfZoeJxJhZMVm9lnfVVWXrw4gVhbL6DAXg7tyQW--z3ZYeB6WLY2yd8OmKv6GzDEyYu6oWNNE0q48tlMHCclx7O0o7Ivfy0aM6ofG6QhRgSJl0WPVrXqO3qKTcBQWkei51kjtrlaufIakVDxRA_gFdiu9-TEOEG0q8tPhmE92QR542z3Y0JVCE-RxqYT3A784sI4wfGkPb62O9iT1OKnbCaEpSKu-a5aI5Cc7JoA5ITVoOUvS5lCLFVcOJzqrTAUj59DZHYXe=w500-h1080-no

whereas Android presents other apps with "Allow management of all files" vs. "Deny":
IC5AKmClOiMkQJxsWhEEYPtz1p7tgdvaP-UYuGKX74wN9EJXMWeNSNQSurr6XUs6NnT6PkeelR-WRIldFNprtowQJQ3UymLR3bx_cg-9wRX8Usi7eWZTsv1jK0Ve_BSBsSMGfMlhGrzY92B-cyOUEl71t_EI8LVYmHHu72cRH3uc9xb2itM0ZIRjjRUrBAPapX0pHLdUNMx3FFWD_Iu0Q6CBKxc0e0zlmOFANP-FR3UQopGSKMpVw1dNxv7e3ckpAPCJhUP6B72AccoJClmvIHWKa9qakLrH51fSniexqaP_eyVd96eL3Awz64cUl84C4w_b940dMzkBIIRwhf6u5BzdyeSIF1LBuokVAbfXJkOVAPqaGgamVU__hm4yzyiHXMhq3yemyVfM86UBy40ZtTkiKTybveW09cmaxVBMaLrTKXrYwOGW6y_LhJ01stJzoaV8rcktZNd3Zb2IojqFOJhR_-kweOy02zXWXJajyMEowxJNAtjSSdnhaSSlWxw7ogJSPujvvqwUrGTkezmfROXsKK-6beRjUyqoLbhAHAFVMmRlZgHBeQtie7I6hdyjbcy7EW_PqP78z9EuftxxItdtBoYoHu_Kbirn1kePsM3wtdWjVOG2Ydlb0NZpOLAuuKCLJ5tbBTHkszCBO8xxz2IkRJpcDiqsOc3lm-uapMkBV-FOF1FAM1grXKDVkrbzLTofSCZUik3SoKnEA0mvrzV1=w500-h1080-no

Maybe one needs to run an ADB command to grant MacroDroid broader file privileges, in order to read files via shell in MacroDroid?

So, back to [COLOR=rgb(44, 130, 201)]adeelshezad230[/COLOR]:
  • Use a shell action invoking the "cat" command, to get the contents of your file into a MacroDroid variable, so you can then parse through it, line by line, using Jacob's macro
  • If you run into permissions issues reading your file in MacroDroid shell actions, try renaming the file (or copying it) to have a media-type extension like .jpg or .mp3 (or, adding permissions via ADB)
 
Top