Possible to search for a semi-colon (or tags with 0 items)?

I’ve just cleaned up a bunch of tags via Applescript and now want to delete the old tags, which are now empty. They were semi-colon delimited, so I’m trying to search for “;”. Unfortunately, I can’t figure out how to do so. I’m guessing the problem is that DT is treating them as “non-white separators”. Regardless, I would love a tip on how to search for them.

Alternatively, given my purpose, is it possible to search for tags that have 0 items associated with them?

Thank you.

This would do it:```
tell application id “DNtp”
set tagList to tag groups of current database

repeat with aTag in tagList
	if (count (get children of aTag)) = 0 then
		log (get name of aTag)
	end if
end repeat

end tell

Another option would be to switch to the Tags view (View menu, As Tags or command-6) where the empty tags will be easy to spot. The empty tags to be deleted can then be selected by command-clicking while any empty tags that you want to keep can be skipped. Scroll through the entire list, and once you’ve made your complete selection, drag them to the trash.

Here’s a riff on @alastor933’s suggestion. Instead of logging the empty tags in moves them to a group “Empty Tag” in the root of the database.


use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

(*
	korm 20160630
*)

tell application id "DNtp"
	set tagList to tag groups of current database
	set emptyTagGroup to create location "/Empty Tags"
	repeat with aTag in tagList
		if (count (get children of aTag)) = 0 then
			move record aTag to emptyTagGroup
		end if
	end repeat
end tell

The script does not delve into tag hierarchies. IOW, a tag “abc” can have child tags and the child tags can all be empty, but because the parent has children it is not empty and is skipped. A clever person can take on the recursion needed to take care of the hierarchies and update the script.

Tags that are moved to the Empty Tag group can be put back and turned into tags again merely by dragging them on top of Tags.

You could also create a smart group:

Item does not contain data
Kind is group

This will return all empty groups (including tags).

1 Like