How to open a random file within a specifed folder?

J1021

Member
Hi all,

I want to open up a random file from within a specified folder on my android device.

It was my favorite website which went down and someone saved it and uploaded the files, so I have the files of this website on my device.

On the website, there used to be a Random Page link that I would enjoy using.

Is there any way to recreate that feature using macrodroid?
I have the files in 1 folder, so I just need a way to randomize opening each link.

I'm a novice so any and all help would be greatly appreciated.

If anyone would be willing to build a macro with this functionality, that would be the best option for me.

Thank you for your time.
 
Last edited:

Dm114

Well-known member
Hi all,

I want to open up a random file from within a specified folder on my android device.

It was my favorite website which went down and someone saved it and uploaded the files, so I have the files of this website on my device.

On the website, there used to be a Random Page link that I would enjoy using.

Is there any way to recreate that feature using macrodroid?
I have the files in 1 folder, so I just need a way to randomize opening each link.

I'm a novice so any and all help would be greatly appreciated.

If anyone would be willing to build a macro with this functionality, that would be the best option for me.

Thank you for your time.
As I guess file names are random, I suggest to load these names in an Array and then pick these names up randomly from 0 to Size (of Array) minus 1.

 

J1021

Member
As I guess file names are random, I suggest to load these names in an Array and then pick these names up randomly from 0 to Size (of Array) minus 1.

The file names are the titles of the articles that were written on the website of which there are 16,000 files in that folder.

Is that in any way feasible to use your suggestion in this case?
(Which, to be honest, is currently beyond me. I'll need to look more into what you suggested a little later.)

Thank you so much for sharing your knowledge with me.
 

Dm114

Well-known member
Hi all,

I want to open up a random file from within a specified folder on my android device.

It was my favorite website which went down and someone saved it and uploaded the files, so I have the files of this website on my device.

On the website, there used to be a Random Page link that I would enjoy using.

Is there any way to recreate that feature using macrodroid?
I have the files in 1 folder, so I just need a way to randomize opening each link.

I'm a novice so any and all help would be greatly appreciated.

If anyone would be willing to build a macro with this functionality, that would be the best option for me.

Thank you for your time.
Something like that:
IMG-20240428-WA0012.jpg
 

Dm114

Well-known member
The file names are the titles of the articles that were written on the website of which there are 16,000 files in that folder.

Is that in any way feasible to use your suggestion in this case?
(Which, to be honest, is currently beyond me. I'll need to look more into what you suggested a little later.)

Thank you so much for sharing your knowledge with me.
Sorry I misread your request and thought they were image files (e.g. of JPEG type).

It's a little bit more complicated but totally feasible. Could you give an example of file names (the whole name with its extension)?
 

Dm114

Well-known member
The only limitation is the amount of data to store 16000 file names... Maybe you'll have to split these files somehow.
 

Dm114

Well-known member
View attachment 9568

I know it's crazy but thank you so much for taking the time to help me.
I really appreciate it!
Ok. It seems to be easy enough. In the example I gave you, just replace "jpg" by "html" and it should work nice. Exccept if names are too long to fit MD memory. If so I'll give you a possible workaround.
 

J1021

Member
Ok. It seems to be easy enough. In the example I gave you, just replace "jpg" by "html" and it should work nice. Exccept if names are too long to fit MD memory. If so I'll give you a possible workaround.
Would it be possible for you to export that macro and upload it here for me to import?
 

Dm114

Well-known member
Would it be possible for you to export that macro and upload it here for me to import?
Sorry but I didn't keep this macro.

Moreover, as it is very short and simple, I'll be a very good exercise for you to create it by yourself (all parameters are visible in the image).

Good luck! You'll quickly love it. 😉
 

J1021

Member
Sorry but I didn't keep this macro.

Moreover, as it is very short and simple, I'll be a very good exercise for you to create it by yourself (all parameters are visible in the image).

Good luck! You'll quickly love it. 😉
I'll give it my best shot and I'll let you know how I get on.
May I ask, how do I learn more about this? What's the name for this kind of thing? I'm clueless.
Thank you.
 

Dm114

Well-known member
I'll give it my best shot and I'll let you know how I get on.
May I ask, how do I learn more about this? What's the name for this kind of thing? I'm clueless.
Thank you.
Good luck.

I'd sent to you the link to MacroDroid Wiki. You should read it to understand how MD (short for MacroDroid) works.

Me or some other users will help you if you need additional explanations.
 
Last edited:

J1021

Member
Good luck.

I'd sent to you the link to MacroDroid Wiki. You should read it to understand how MD (short for MacroDroid) works.

Me or some other users will help if you need additional explanations.


1000036887.jpg
Me again.
Definitely over my head.
I'm doing somethings wrong but I don't know what.
1. There are extra brackets in the text manipulation thing.
2. Set variable is showing 2 things.
3. Open file with isn't showing me my browser as an option.
4. In local variables there is an extra B option that comes back everytime.
5. When I test actions, it says in the notifications "Could not launch /blog/{lv=Array[0]}.html" .

I really think I've given this a fair try. I'm just trying to open a random Web page. I'm not a developer in any sense.

Do you think you could possible help me a little further.

Even possibly building that macro again and sending it to me please.

I would seriously appreciate that.
Thank you for all of your help thus far!
 

Dm114

Well-known member
View attachment 9573
Me again.
Definitely over my head.
I'm doing somethings wrong but I don't know what.
1. There are extra brackets in the text manipulation thing.
2. Set variable is showing 2 things.
3. Open file with isn't showing me my browser as an option.
4. In local variables there is an extra B option that comes back everytime.
5. When I test actions, it says in the notifications "Could not launch /blog/{lv=Array[0]}.html" .

I really think I've given this a fair try. I'm just trying to open a random Web page. I'm not a developer in any sense.

Do you think you could possible help me a little further.

Even possibly building that macro again and sending it to me please.

I would seriously appreciate that.
Thank you for all of your help thus far!
Let me have a look...
 

Dm114

Well-known member
View attachment 9573
Me again.
Definitely over my head.
I'm doing somethings wrong but I don't know what.
1. There are extra brackets in the text manipulation thing.
2. Set variable is showing 2 things.
3. Open file with isn't showing me my browser as an option.
4. In local variables there is an extra B option that comes back everytime.
5. When I test actions, it says in the notifications "Could not launch /blog/{lv=Array[0]}.html" .

I really think I've given this a fair try. I'm just trying to open a random Web page. I'm not a developer in any sense.

Do you think you could possible help me a little further.

Even possibly building that macro again and sending it to me please.

I would seriously appreciate that.
Thank you for all of your help thus far!
Don't forget to check the exact path of the folder where your html files are stored (the 1st Shell script action).
 

Attachments

  • Tst.macro
    4.1 KB · Views: 3

J1021

Member
Don't forget to check the exact path of the folder where your html files are stored (the 1st Shell script action).
Unfortunately not.
When I click test actions, I get a notification that says "Could not launch /MacroDroid/.html" .

Also, do I need to put an * after the folder location? I tried with and without to the same error.

Thank you again.
I really appreciate it.
 

Dm114

Well-known member
Unfortunately not.
When I click test actions, I get a notification that says "Could not launch /MacroDroid/.html" .

Also, do I need to put an * after the folder location? I tried with and without to the same error.

Thank you again.
I really appreciate it.
Is this the message you get when testing Open file action?

How many items are they in the Array variable? If zero, that means that the "cd" command (Shell script) is wrong.

What is the content of "s" variable after running the macro?
 

J1021

Member
Is this the message you get when testing Open file action?

How many items are they in the Array variable? If zero, that means that the "cd" command (Shell script) is wrong.

What is the content of "s" variable after running the macro?
Yes. Both when I press on the three dots at the top right and then click on "test actions" but also when I click on the "open file" action and click "test action".

There is 1 entry.

The "s" variable says "<empty>"

The notification says
"Open file failed
Could not launch/MacroDroid/.html"

Thank you.
 

Dm114

Well-known member
Yes. Both when I press on the three dots at the top right and then click on "test actions" but also when I click on the "open file" action and click "test action".

There is 1 entry.

The "s" variable says "<empty>"

The notification says
"Open file failed
Could not launch/MacroDroid/.html"

Thank you.
Undoubtedly your path is not good.

What is the exact "cd" command you have and how did you find the path?
 
Last edited:

Dm114

Well-known member
Yes. Both when I press on the three dots at the top right and then click on "test actions" but also when I click on the "open file" action and click "test action".

There is 1 entry.

The "s" variable says "<empty>"

The notification says
"Open file failed
Could not launch/MacroDroid/.html"

Thank you.
I forgot to say that you have to customize the folder in the Open file action.
 
Top