Get results of Finder search as input using Applescript/shell script
I have created a workflow in Automator that uses a shell script to open a random file in a selected folder. What I really want to do is to be able to search across folders and open a random file using the search results as input.
My first thought was that there must be a way to do a search in finder and then get the contents of the active finder window (i.e. the search results) as input for my workflow, but everything I can find requires using a defined location as input.
Is there a way to accomplish what I want to do? It seems like it would be simple, but I know that's not always the case.