Exclude Library folder from being searched with find command in Terminal–OS X Mavericks

198 Views Asked by At

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?

1

There are 1 best solutions below

2
On BEST ANSWER

Originally tagging your question with or, more specficially, would have gotten it more attention ( 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.