Noob: Play random sound from a folder using "play sound" action

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.

1 Like