Smart Folder Exclude Folder

Ultimately I want the result of this find command to be a smart folder.

The criteria aren't that complicated:

  • name should be "README.md"
  • type should be file
  • path should not contain "node_modules"

find /Users/me/Documents -type f -name README.md -not -path "*/node_modules/*"

The problem is that the smart folders criteria operator list seems to be lacking a does not contain option.

The available options are:

  • matches
  • contains
  • begins with
  • ends with
  • is
  • is not

Is it possible to accomplish this and if so then how?

Edit 1

I found that by holding the option key I am able to add a negation clause to the smart folder search criteria but I cannot seem to successfully exclude the node_modules folder. It is unclear which criteria to use but none of the ones I have tried seem to work:

  • Document Container
  • Containing Folder Names
  • Folder Name

I have tried combining these with the following operators:

  • contains
  • matches

and with the following terms:

  • node_modules
  • node_modules

in case it supports wildcard searches.

I have tried all combinations of the above filters, operators and terms.

The documentation is so poor on the subject.

enter image description here

  • 3
    Have you found a solution?
    – gota
    Commented Nov 27, 2015 at 10:41

4 Answers 4


It looks like kMDItemPath can't do what you need:


Some potential alternatives are discussed here:


  • 1
    Thanks but I already have a command line function that retrieves the files I am interested in and I am making a Smart Folder, not doing a spotlight search. I have come across the limitation of mkdItemPath.
    – km6zla
    Commented Jun 4, 2014 at 19:27
  • Spotlight Search and Smart Folders use the same internal mechanism. kMDItemPath won't work in either of these user interfaces. Commented Jun 5, 2014 at 3:19

There is a workaround, but it's not very pretty. It will, however, serve your purposes if you just want to access your READMEs in one folder (using the criteria you've specified), and have some notion of where they come from.

The idea is to use your shell script to find the right files, and then collect aliases to each file in one directory. We then rename the aliases to tell us what parent directory the original file belongs to.

The Applescript to do this is below. It looks ugly here, but try pasting it into Script Editor and compile it, and you should be able to see the logic.

--- Set up the name of the folder to contain search results
set myFolder to POSIX file "/Users/me/SmartFolder"

--- Clear the folder of contents. Then we will see only the results of an updated search
tell application "Finder"
    display dialog "WARNING. This will delete all files below " & (POSIX path of myFolder) & " . Are you sure you want to continue?"
    delete (every item of folder myFolder)
    --- alternatively, if you want to keep your script in the same folder, replace the line above with
    --- delete ((every item of folder myFolder) whose name does not end with ".scpt")
end tell

--- The shell command that is doing all the searching
set FileList to do shell script "find /Users/me/Documents -type f -name README.md -not -path '*/node_modules/*'"

--- The rest of the script takes each file and makes an alias in our folder containing search results. The aliases are renamed according to "ParentDirectory_filename"
set FileList to paragraphs of FileList
repeat with CurrentFile in FileList
    set ASCurrentFile to POSIX file CurrentFile
    set PathList to words of (ASCurrentFile as string)
    --- Make the new name include the Parent Directory and file name
    set NewName to (item -2 of PathList) & "_" & (item -1 of PathList)
    tell application "Finder"
        make new alias file at myFolder to ASCurrentFile
        --- We need to save the name/location of the new alias file before we can try to rename it
        set NewAlias to result
        set i to 1
                --- Try to rename the alias. Won't work if there's already an alias with the new name
                set name of NewAlias to NewName
                exit repeat
            on error
                --- Append a number to the alias. Increase the number for more duplicates
                if i is not equal to 1 then
                    set NewName to text 1 thru -3 of NewName
                end if
                set NewName to NewName & " " & i
                set i to (i + 1)
            end try
        end repeat
    end tell
end repeat
  • I don't know if this works. +1 for even coming up with it. I'm not willing to go this far to make a readme folder.
    – km6zla
    Commented Mar 29, 2017 at 22:55

When doing a Raw Query just add this:

(kMDItemPath != "folder to exclude")

@David, from the documentation for kMDItemPath:

"Complete path to the file. This value of this attribute can be retrieved, but can't be used in a query or to sort search results. This attribute can’t be used as a member of the valueListAttrs array parameter for MDQueryCreate or MDQueryCreateSubset."

I tried it and it does not work


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .