Open dstadulis opened 3 months ago
Instead of searching for files and then post-qualifying them to those that don't contain the tags, is is possible to make this work by forming the metadata query to search for those without tags in the first place?
Currently the code does this:
else // if tagSet count > 0
{
NSMutableArray* subpredicates = [NSMutableArray new];
for (TagName* tag in tagSet)
[subpredicates addObject:[NSPredicate predicateWithFormat:@"%K ==[c] %@", kMDItemUserTags, tag.visibleName]];
result = [NSCompoundPredicate andPredicateWithSubpredicates:subpredicates];
}
Is it possible to make something like this work?
else // if tagSet count > 0
{
NSMutableArray* subpredicates = [NSMutableArray new];
for (TagName* tag in tagSet)
if negativeTagSearch {
[subpredicates addObject:[NSPredicate predicateWithFormat:@"%K !=[c] %@", kMDItemUserTags, tag.visibleName]];
} else {
[subpredicates addObject:[NSPredicate predicateWithFormat:@"%K ==[c] %@", kMDItemUserTags, tag.visibleName]];
}
result = [NSCompoundPredicate andPredicateWithSubpredicates:subpredicates];
}
These changes introduce a new feature to the
tag
command-line tool: the ability to find files that do not contain any of the specified tags. This is achieved through the addition of two new operation modes:OperationModeInvertFind
: This mode is triggered by the-F
or--invert-find
option, and it causes the tool to search for files that do not contain any of the specified tags.doInvertFind
is added to theTag
class to handle this operation mode. This method calls another new method calledfindFilesWithoutTagWithUsage:NO
, which performs the actual file search.The changes also modify the existing help text and man page to document the new feature.
Here's a summary of the key changes:
OperationModeInvertFind
and a new methoddoInvertFind
to handle it.findFilesWithoutTagWithUsage:NO
, which performs the actual file search for files that do not contain any of the specified tags.Demonstrating these changes enable users to find files that do not contain specific tags: