Is there a way to programmatically isolate tags with nothing in them?

I don’t know what to call this, so this picture is key:

First, what do you call the numbers in the red box? And second, how do you access those, either in AppleScript or with a Smart Rule?

My goal, quite simply, is to create a “tag sweep” command that goes through various Databases and collects all these “empty tags” into a single “#Empty” tag. Or even just deletes them.

Also, is tag group something that only matters if you’ve got DT3 set to where Groups are also tags?

Thanks!

Here is something you could use. It was originally posted before by Christian, the developer.

Thanks, I just found that. A slight variation: is there a way to do the same thing for Tags with exactly 1 entry? This is common due to some…err…mistakes made in the past. :slight_smile:

While we’re at this, any clever way to clean up this mess of weirdly duplicate tags?

I don’t use tags so I’ve no real experience but this should do it. Select all tags, run the script. It collects the children under one instance of a tag and moves empty tags to the trash.

Use a test database first!

-- Deduplicate Tags

tell application id "DNtp"
	try
		set selectedTags to selection of think window 1
		
		repeat with thisTag in selectedTags
			set theGroup to create location (location of thisTag) & "/" & (name of thisTag) & "/" in current database
			set theChildren to children of thisTag
			
			repeat with thisChild in theChildren
				move record thisChild from thisTag to theGroup
			end repeat
			
			if (count of children of thisTag) = 0 then
				move record thisTag to trash group of current database
			end if
		end repeat
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
	end try
end tell

Are you looking at the top level Tages group, or the Tags for a given database. They are not the same. The top level one is a union of all the Tags for all open databases.

If you are looking at the tags for one group, you can simply choose both groups and choose Tools > Merge.

One database, I have my tags currently set to not be unified. I forgot about the Merge command. Which brings me back around to my question re automation: can you automate merging and more importantly, can I programmatically access the number of items within a tag. I have TONS of “1 item” tags that are usually an accident or caused by importing RSS items or pictures (I’ve since turned off most automatic tag creation, though I’d like to be able to put it back on if I could easily maintain the tag database). Thanks!

Have a look at How do you sort Tags by number of Items? - DEVONthink - DEVONtechnologies Community.

Ah, thanks for the link. Basically the answer right now is “this can be done in a hacky way but there is no official support for it.” Your script looks helpful, but at the moment, the only thing I need to do is identify tags with just 1 item and I can more or less do that manually fairly quickly.