Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dexterous_

macrumors newbie
Original poster
Jan 1, 2016
2
0
Looking for some help with what I think should be an achievable script.

Basically looking for a script that will search subfolders for specific files types (mp3, mp4, m4a) and select one random file from each subfolder, then write this into an m3u.

The following creates an m3u per subfolder but this isn't what I am after:

find . -name ‘*.mp3’ -execdir bash -c ‘file=”{}”; printf “%s\n” “${file##*/}” >> “${PWD##*/}.m3u”‘ \;

Assistance greatly appreciated :)
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,618
6,147
How does that differ from what you want?

Also, why are you subjecting yourself (or anyone else) to the horrors that are bash?
 

dexterous_

macrumors newbie
Original poster
Jan 1, 2016
2
0
Would it be possible in applescript?

Am after a single m3u file that contains one random file from each subfolder.
 

sero

macrumors member
Aug 28, 2008
91
14
This won't be too hard. Just start with getting a basic find command to return what you want. Then pipe that through a command to randomize the order (I always forget what the BSD work around is for 'sort -R' - you can find it easily enough though) and store it. Then grab the 2nd to last fields separated by '/' - this will be the parent dir name for each file. Pipe that through 'sort -u'. Then you have a list of unique dirs. Now loop through the randomized list and grep each unique dir and pipe the output through head or tail, then redirect to your m3u. done
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.