I'm trying to make an AppleScript that searches for a specific folder called keyPRO inside the user's home folder. I'm using the following code in my AppleScript to do this:
do shell script "find ~/ -name 'keyPRO'"
(The "~/" means search inside the current user's home folder.)
What's annoying is that every time I run it, Terminal searches inside my Library folder which causes a "Permission denied" error, as well as other random stuff showing up.
Is there a way to exclude the user's Library folder from being searched?
Originally tagging your question with shell or, more specficially, find-util would have gotten it more attention (terminal doesn't come into play here - AppleScript's do shell script
doesn't open a terminal window, it merely creates a shell child process.).
do shell script "find ~ -path ~/Library -prune -o -name 'keyPRO' -print"
will exclude ~/Library
from your find command.
From a shell, run man find
for more information on the find
command.
However, note that you wouldn't ordinarily see warnings or error messages when you use AppleScript's do shell script
, unless the shell command fails (reports a nonzero exit code) as a whole (in which case AppleScript throws an error with the shell error message as the description).
Warnings and error message are sent to the stderr stream, whereas do shell script
by default only captures stdout.