So I don't know how to do this with native AppleScript, but because Macs use Bash, you can use a shell script to do the searching. It's not ideal but it's better than nothing.
So your shell script is going to
cd, change directory, into the folder you need to search. Then, it'll execute the
ls command, which lists the contents of a directory. the
-a flag on
ls tells it to list hidden items. Bash tools use a concept called standard input/output to get input and display output. The standard output is displayed on screen by default, but it can be redirected by a tool called a pipe to go somewhere else. In this case, instead of displaying a list of all the files in a directory, we're going to pipe that list into a search tool called
grep. That explanation was somewhat verbose but your shell script only needs 3 lines (the first of which is arguably unnecessary in this case):
#!/bin/bash # define the shell, not really needed because bash is the default shell but good practice
cd /path/to/search/directory # cd to the proper place
ls -a | grep "the text you're looking for" # list all files (including hidden ones) and pipe output into grep, a search tool
Save this as something logical, like
findFile.sh, then make it executable with this command in the terminal app
chmod +x /path/to/findFile.sh
So now that's ready to go, on to the AppleScript.
Like I said I'm not that experienced in AppleScript, but as I understand it you'd run the shell script like this
set output to do shell script "/path/to/findFile.sh"
output variable would contain any text that grep found. Your test for whether or not the file exists is now whether or not
output contains any text.
Feel free to run
man grep in the terminal for the
grep manual to see more about how it works and what it matches and how to only match files with certain extensions and stuff like that. Perhaps you may want to play around piping things into
grep to get a feel for how it works.
Hopefully someone can come along with an answer to your question in AppleScript.