I do something similar myself in one of my macros, but the files are images to search the screen for rather than sounds. I will have to go find it, although what I possibly did was get a list of the files and shuffle the list then take the first one from the list.
There may be a simpler way, if you redefine "random" to mean "use the files in rotation." You see, KM has an action called For Each which allows you to search on "The Items in Directory" and you can sort by "date last used" and you can click the button "reversed". If you do this, then the first file in that search will probably be the last file used. You can break from the loop at that point. This trick should work because each time you access the file to play it, the "last used date" is probably updated to the current time.
Here's a solution that I found on this website:
That solution was intended to search subdirectories too, but that shouldn't be a problem for you.
Okay, here's some simple code that will play files in a "cyclical order" (not random order). I was really trying to make this code even simpler, but for some reason I can't understand, opening a file doesn't change the "last used data" on a file. I guess maybe it's only when the file is written that a file is "used". I'm going to continue to research that, but for now you will need the action that "touches" the file in order to change its date.
is there any way to incorporate the "play sound" action instead of playing through an application? I don't really have an application that I want to play these through – the "play sound" option is really a perfect option for this!
I didn't think of that. Let me think about it. It appears that KM allows you to play files by name, but you have to select the name when you write the macro. This is one of the very rare cases where KM lacks flexibility!
I'm not sure if the folder you indicated is a folder or a file (that's one of the goofiest folder names I've ever seen.) Are you sure the folder name actually ends in "[mp3]"?? More likely, you thought that's how to specify a bunch of files, but if that's true, you are not correct. Please confirm the exact name of your folder. Are you sure the folder name is:
/Volumes/OchoSupreme/[ 0 ] W I P/atHELLO/atHELLO clips [mp3]
Minor detail: if you deleted the IF statement, then you don't need the Split action. But depending on how you answer the first question, you may need to put the IF statement back in.
clarification: after looking at the folder name again, I realized I originally wanted to name the folder "@Hello" but my mac didn't like the "@" – so I had to spell it out. So, I was wrong: even macs don't let you do ANYTHING!
fwiw, these sound files are all movie quotes, which is where @Hello comes from – "you had me at hello"
Since your code looks good, I'm guessing it's the crazy folder name, so I want you to open a Terminal window and then copy and paste this line into it.
ls /Volumes/OchoSupreme/[ 0 ] W I P/atHELLO/atHELLO clips [mp3]
I suspect it will fail because it looks like your folder name has multiple consecutive spaces, and since you didn't post the actual macro and I can't count the spaces out of your image, I need you to use the ls command on the folder name and tell me what it outputs.
Basically, my macro is so short that there's hardly anything that can go wrong except your folder name.
I just changed the name of the folder and also the location to this: ~/Desktop/audioClips
and it works!
I don't really understand what it's doing though. I thought it would just play them in the order listed in the folder. Instead, it's playing a random one, then changing the modified date... which is fine with me; just not what I expected.