Search for a specific tag

How do I find all items that have only one specific tag and no other tags?

For example, items that have tag tag1 and only tag1.

Have you tried typing into the search field tag:nameofyourtag

Yes, that solves only part of the question. It finds all items with that tag but doesn’t exclude items that have other tags on them.

OR

Just type:
tag=TagYouWant tag!=TagYouDon't

I know about this. Unfortunately, this gets tedious very quickly and I have very many tags. This is also not suitable for a saved search as I add new tags often.

Perhaps you would consider explaining why you want to do this search, and there might be other ways to accomplish the task.

For example, if we are just talk about a few hundreds of files in a group, just use “tag is” and kind is any document, and add the column “Tags” in the list view. A simple sort using the “Tags” column will let you visually spot out the files with only one tag easily. Now, if you are talking about many thousands of items in the entire database, that’s a different story.

I have a few orthogonal groups of tags and want to make sure that all items are tagged in all groups.

For example, there are two groups of tags. One for shape and one for color. There are only two shapes: round and square. But there are dozens of colors and the list is growing all the time.

In this example how do I find items that do not have a color tag on them?

Conditions
(1) Your groups of tags are right under “/Tags” (e.g. Tags/Color and Tags/Shape), and
(2) You are looking at two groups of tags only, and
(3) You want to find those items that are tagged in the first tag group but not in the second group.

Then this script will find those records that are tagged under the first main groups ( shape) but not under the second main group (color), or vice versa. The script will ask you to choose the first main group from a list , then ask again for the 2nd main group from a list, then shows those records in a viewer window.

Noted that:
(1) I haven’t tested this quick and dirty script thoroughly, but it works on a limited sample for me.
(2) There must be some smarter way by using the smart rule function. Wait for the others to respond if you wish.
(3) The scope of the search is the entire database. If you have many items in the database, perhaps you should change the scope in the script to the group’s name.
Finally, not an ideal solution if you need to constantly update the search. Wait for the others to help suggesting a longer term solution.

tell application id "DNtp"
	set theTopTags to get record at "/Tags"
	set theMainTagGps to name of children of theTopTags
	set theFirstMainTag to (choose from list theMainTagGps with prompt "Items that are under this tag group")
	set theRecords to search "tags:" & theFirstMainTag & " kind:any scope:database"
	
	set theSecondMainTag to (choose from list theMainTagGps with prompt "But are not under this tag group")
	
	set theResults to {}
	repeat with eachRecord in theRecords

		set theTags to (tags of eachRecord)
		
		if theTags contains theSecondMainTag then
		else
			set end of theResults to eachRecord
		end if
		
	end repeat
	set search results of viewer window 1 to theResults
	
end tell



1 Like

Haven’t tested yet but looks promising. Thank you.

I wonder if there’s a way to make it a smart group or any other way to put it into Navigate sidebar?

Someone should know but not me…it’s probably a mistake[big] for me not to learn more about smart rule!

Assuming that “Color” is a tag containing all the colors, then adding the condition Tag… is not… Color should be sufficient.