This is a script that selects a random pdf from a particular folder and reveals it in Finder. But it only selects a pdf from the top level of the folder. How can I get it to look into subfolders as well?
set j to "Macintosh HD:Users:me:Documents:pdfs"
tell application "System Events"
set all_pdfs to path of every file in folder j whose visible = true and name extension is "pdf"
end tell
set random_pdf to some item of all_pdfs
# uses an existing window or makes a new window with your default settings
tell application "Finder"
reopen # makes a new window if there are no open windows
activate
set target of window 1 to random_pdf
end tell
note: I'm using System Events because it's much faster than Finder.
find
.entire contents
) without you explicitly doing it, as mentioned in my previous comment and your linked topic.do shell script "mdfind -onlyin " & "~/Documents/" & " -name '.pdf'"
. Offhand, I think the 'as alias' may be redundant.