Process Files Displayed in Smart Folder (Saved Search)

Which confused me, because I found it on my Mojave machine...

I think it just hasn't made it into the man page. Going back through the Terminal history it appears I stumbled on it by typing mdfind without any arguments, and the -s option appears in the Usage message.

FWIW I'm on Ventura.

So was I for testing. I even set up a tags search in case those were the problem:

nigel@Nigel's-MacBookAir ~ % mdfind -s "Blue Tags"
/Users/nigel/Desktop/r3.png
/Users/nigel/Desktop/r4.png
/Users/nigel/Desktop/r5.png
/Users/nigel/Desktop/r6.png

And it isn't that you've saved your search somewhere other than ~/Library/Saved Searches because that would get you a "Could not find..." error.

I can get the same result as you when there isn't actually anything to find -- but I'm assuming it isn't that!

2 Likes

Eh?

Ha! Sure enough, you're right.

It's not listed in the man page, but it is listed in the help:

$> mdfind -h

-attr <attr>      Fetches the value of the specified attribute
-count            Query only reports matching items count
-onlyin <dir>     Search only within given directory
-live             Query should stay active
-name <name>      Search on file name only
-reprint          Reprint results on live update
-s <name>         Show contents of smart folder <name>
-0                Use NUL (``\0'') as a path separator, for use with xargs -0.

Is it listed on the man page in Ventura?

This is the output of that common in Ventura:

mdfind -h

Usage: mdfind [-live] [-count] [-onlyin directory] [-name fileName | -s smartFolderName | query]
list the files matching the query
query can be an expression or a sequence of words

	-attr <attr>      Fetches the value of the specified attribute
	-count            Query only reports matching items count
	-onlyin <dir>     Search only within given directory
	-live             Query should stay active
	-name <name>      Search on file name only
	-reprint          Reprint results on live update
	-s <name>         Show contents of smart folder <name>
	-0                Use NUL (``\0'') as a path separator, for use with xargs -0.

example:  mdfind image
example:  mdfind -onlyin ~ image
example:  mdfind -name stdlib.h
example:  mdfind "kMDItemAuthor == '*MyFavoriteAuthor*'"
example:  mdfind -live MyFavoriteAuthor

No, it isn't. I'll try and find a "standard install" machine next week, just in case it's a tweak from the Xcode Command Line Tools (which I'm guessing yourself and @unlocked2412 have installed, but @noisneil may not).

1 Like

I definitely have Xcode and I think I installed CLT although it would have been quite a while ago so I'll check.

Regardless, I don't see how this would help me trigger the macro upon tag removal.

It wouldn't. I'm partly scratching the itch I always get when a seemingly simple command works on one machine but not another, but also this would be a quick way to compare the contents of your Smart Folder to determine what had been untagged and so was due for removal from Dropbox -- that could be done on a periodic basis or as part of your macro. In pseudo-code

do shell script 'mdfind -s "smartFolder"' saving results to Local_taggedFiles
repeat with each item Dropbox location
   if (munged path to item) is not in Local_taggedFiles then delete item
end repeat

Comparing the Dropbox path to the original path would take some fiddling, but I'm assuming that since you've macroed the copying there would be consistent placement on that end -- so it would "just" be determining the relevant portion of the original's path to compare against.

1 Like

I've already managed it using the comments hack, which is the only way I could think of, given that the tagged folders aren't actually being copied but the files-of-type within them.

1 Like

I can confirm I have installed Xcode Command Line Tools. Not sure whether that information comes with this installation.