How to open a random file within a specifed folder?

Dm114

Well-known member
First of all, test Script shell action alone once you find the right path and look at the content of "s" variable after test. It should contain all the .html file names found in the indicated folder.
 

Dm114

Well-known member
Please read MD Wiki at least for the couple of actions used in this macro in order to understand what and how they are supposed to work.
 

J1021

Member
I forgot to say that you have to customize the folder in the Open file action.
1000036890.jpg

I changed the path in the "open file" action and now the notification says
"open file failed
Could not launch /blog/.html"

I got the path location from the "properties" in the "cx file explorer" app.
There are more files than this screenshot shows as I took it while it was still counting.

Thank you once again!
 

J1021

Member
First of all, test Script shell action alone once you find the right path and look at the content of "s" variable after test. It should contain all the .html file names found in the indicated folder.
In the shell script configuration, the "Is * .html" has a space after the asterisk. Is that supposed to be there?

The "s" variable, is that the "local variables" tab?
It still shows <empty> after I tested the Shell script on its own.

I do apologise, this really is beyond me. I've started reading the wiki and I simply don't have the background knowledge to connect much of what I'm reading to the very little that I do know.

Please let me know if this is a waste of your time.

I would like to get this working someway for others in the future as well.

Even an app in the play store that I can navigate to a specific folder and randomly open any file within it.

Thank you and apologies.
 

Dm114

Well-known member
In the shell script configuration, the "Is * .html" has a space after the asterisk. Is that supposed to be there?

The "s" variable, is that the "local variables" tab?
It still shows <empty> after I tested the Shell script on its own.

I do apologise, this really is beyond me. I've started reading the wiki and I simply don't have the background knowledge to connect much of what I'm reading to the very little that I do know.

Please let me know if this is a waste of your time.

I would like to get this working someway for others in the future as well.

Even an app in the play store that I can navigate to a specific folder and randomly open any file within it.

Thank you and apologies.
Of course there shouldn't be any space between * and .html

Please check the complete path in the "cd" command of the Shell script (as I already told you) from /storage/... untill .../blog/
 

J1021

Member
Of course there shouldn't be any space between * and .html

Please check the complete path in the "cd" command of the Shell script (as I already told you) from /storage/... untill .../blog/
1000036895.jpg

cd /storage/3965-3538/Documents/AJATT/AJATT/www.alljapaneseallthetime.com/blog/
ls *.html

Here's a screenshot and the text copied. Hopefully this helps.

Sorry for the delay.
I'm in the United Kingdom.
 

J1021

Member
So, now, it should work
1000036903.jpg


No such luck.

I don't know how much more patience I have for this.

Do you know of any other (simpler) way of achieving this even outside of macrodroid? Any apps etc?

I cannot thank you enough for being so patient with me and my lack of knowledge in this field, and taking the time to work through this with me.

It truly is greatly appreciated!
Thank you.
 

Dm114

Well-known member
View attachment 9586


No such luck.

I don't know how much more patience I have for this.

Do you know of any other (simpler) way of achieving this even outside of macrodroid? Any apps etc?

I cannot thank you enough for being so patient with me and my lack of knowledge in this field, and taking the time to work through this with me.

It truly is greatly appreciated!
Thank you.
The problem comes from this very complicated path name. I would suggest to rename this path in something much more simpler.

As far as I understood, it is stored on a SD card. Try to move your files to a folder located at the root level. Something like "MyFiles" and the "cd" command would be easier: cd /storage/3965-3538/MyFiles/
 

Dm114

Well-known member
View attachment 9586


No such luck.

I don't know how much more patience I have for this.

Do you know of any other (simpler) way of achieving this even outside of macrodroid? Any apps etc?

I cannot thank you enough for being so patient with me and my lack of knowledge in this field, and taking the time to work through this with me.

It truly is greatly appreciated!
Thank you.
There is nothing complicated: it's hard to have less than 4 actions to achieve what you're looking for...

Be very rigorous when typing commands.

To solve this problem of path, when you change it (simplify it), just test the Script shell action and look at the content of the "s" variable.
 

J1021

Member
There is nothing complicated: it's hard to have less than 4 actions to achieve what you're looking for...

Be very rigorous when typing commands.

To solve this problem of path, when you change it (simplify it), just test the Script shell action and look at the content of the "s" variable.

As you can see from the previous screenshot, I made a "testdelete" folder with only a few of the html files in it, located on my device itself under main storage.
I changed the location in both the Shell script and the open file action.

Whenever I tested the Shell script action on its own, the s variable still shows <empty>.

I'm really not sure what could possibly be wrong?

Thank you again.
 

Dm114

Well-known member
As you can see from the previous screenshot, I made a "testdelete" folder with only a few of the html files in it, located on my device itself under main storage.
I changed the location in both the Shell script and the open file action.

Whenever I tested the Shell script action on its own, the s variable still shows <empty>.

I'm really not sure what could possibly be wrong?

Thank you again.
I can't see your screenshot: where is it? 🤔
 

J1021

Member
Above the words "no such luck"

It might be at the bottom of the post saying something like "view attachment".
 

Dm114

Well-known member
Above the words "no such luck"

It might be at the bottom of the post saying something like "view attachment".
Sorry but I think you don't really understand what you're doing nor follow the steps to debug this so simple macro...

The attachment shows the MacroDroid error message about Open file. Which is completely normal.

We need to know how Script shell action works. "s" variable can't be empty in any way as it contains the result of the "cd" and "ls" command which is either a system error message or the list of all the html files located in the folder described in the cd command.

So if you want to make this macro work, test Script shell action first with the new parameters and look at the content of "s".

Could you please send a screenshot on of this Shell script action?
 

J1021

Member
Sorry but I think you don't really understand what you're doing nor follow the steps to debug this so simple macro...

The attachment shows the MacroDroid error message about Open file. Which is completely normal.

We need to know how Script shell action works. "s" variable can't be empty in any way as it contains the result of the "cd" and "ls" command which is either a system error message or the list of all the html files located in the folder described in the cd command.

So if you want to make this macro work, test Script shell action first with the new parameters and look at the content of "s".

Could you please send a screenshot on of this Shell script action?
1000036905.jpg

This screenshot was taken after I clicked on shell script, test action.

I cannot stress enough how out of my depth I am when it comes to this stuff.
I'm sorry that this is frustrating for you.
Thank you so much for your patience with me.
 

Dm114

Well-known member
View attachment 9587

This screenshot was taken after I clicked on shell script, test action.

I cannot stress enough how out of my depth I am when it comes to this stuff.
I'm sorry that this is frustrating for you.
Thank you so much for your patience with me.
Sorry but I asked for screenshot of the Shell script action not of the whole macro.

I mean with all the parameters of this action.
 

Dm114

Well-known member
I will also need same screenshot for next action: Text manipulation. Please.

We should get rid of all this stuff in a couple of minutes! 😉
 

J1021

Member
Sorry but I asked for screenshot of the Shell script action not of the whole macro.

I mean with all the parameters of this action.
1000036906.jpg

Sorry.

I checked the md helper app and it gave me a message when I went on it.
Now the s variable is getting populated.
And my browser is opening, which is progress.
However, it's not opening any file. Just opening the browser to the default Google page.
 

Dm114

Well-known member
View attachment 9588

Sorry.

I checked the md helper app and it gave me a message when I went on it.
Now the s variable is getting populated.
And my browser is opening, which is progress.
However, it's not opening any file. Just opening the browser to the default Google page.
We nearly won!

Thanks for sending last screenshot (Text manipulation)
 
Top