Remove tags

Searching the forum doesn’t seem to bring up an easy answer, or at least I haven’t found one.

I can view the tag definitions in a library by looking at “as Tags” view or bring up the Groups & Tags HUD. Is there a way of removing

  1. a tag definition that is either in use or not (if in use, remove the tag from the documents, but not deleting the documents), and

  2. a tag from a collection of documents (several highlighted or a group whose documents all contain the tag in question) without removing the tag definition itself and without removing the tag from other documents that are not selected or in the group currently selected.

I’ve tried deleting the tag definition using delete keys without success. The edit menu doesn’t provide a way. Right-click menu doesn’t provide a way. Dragging the tag off the window doesn’t work. What’s irritating is that I’ve been able to do it before, but I don’t know which of the random methods I was trying actually did it. (I’m also not sure whether documents disappeared when a I managed to remove a tag - don’t think so.)

It’s a mystery!

Open the Tags group in the database, find the tag (it’s a subgroup of Tags). Delete it. The documents will not be deleted; the tag will; and the tag is removed from all documents on which it appeared.

The script below was originally posted in this thread, based on a suggestion of @acoyne’s. Now that I look at it, I think it could be a bit more elegant - but it works. :confused:

-- remove a tag from selected documents
-- based on a concept of @acoyne

tell application "DEVONthink Pro"
		set theSelection to the selection
		if theSelection is {} then error "Please select some contents."
		set listTags to (name of every tag group of current database)
		choose from list listTags with prompt {"Delete tag from \"" & name of current database & "\""} default items ""
		-- choose from list listTags with prompt {"Delete tag from \"" & name of current database & "\""} default items "" with multiple selections allowed
		set searchString to result as list
		repeat with theItem in theSelection
			set theTags to the tags of theItem as list
			if searchString is in theTags then
				set newTags to "" as list
				repeat with thisTag in theTags
					if thisTag is in searchString then
						copy "" to the end of newTags
						copy thisTag to the end of newTags
					end if
				end repeat
				set the tags of theItem to newTags
			end if
		end repeat
	on error error_message number error_number
		if the error_number is not -128 then
				display alert "DEVONthink Pro" message error_message as warning
			on error number error_number
				if error_number is -1708 then display dialog error_message buttons {"OK"} default button 1
			end try
		end if
	end try
end tell

Thanks. I just wasn’t having luck finding answers before - I’ll have to pdf your comment and script and add it to DTPO for future reference! And I’ll add that script to the library.