Some improvements for tagging

  1. There ought to be some way to batch-delete tags from some items, but not others. Right now, you can remove them one at a time, or from all at once. I’ve written a script (see below) to allow deleting specified tags from selected items, but unfortunately it runs all the remaining tags for that item together (anyone got a fix?)

  2. Right now new folders are automatically tagged, as are all items within a tagged folder. There should be a preference setting giving users the option of turning each of these off.

Okay: here’s that script I mentioned:```
tell application “DEVONthink Pro”
activate
try
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)
	set chooseTag to choose from list listTags with prompt {"Delete tag from \"" & name of current database & "\""} default items "" with multiple selections allowed
	
	set searchString to chooseTag as string
	set replacementString to ""
	
	repeat with theItem in theSelection
		set theTags to the tags of theItem as string
		
		if theTags contains searchString then
			set AppleScript's text item delimiters to searchString
			set text_item_list to every text item of theTags
			set AppleScript's text item delimiters to replacementString
			set newTags to text_item_list as string
			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
		try
			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

You can exclude each group from tagging via the Info panel or all of them via the Database Properties panel.

Try this

-- remove a tag from selected documents
-- based on a concept provided by acoyne May 17, 2010
-- http://www.devon-technologies.com/scripts/userforum/viewtopic.php?f=4&t=10905&start=0

tell application "DEVONthink Pro"
	activate
	try
		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 ""
		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
					else
						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
			try
				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, korm! Er, I don’t suppose there’s any way to make it work for multiple tags?

Sure is.

Oh, yes, you’re right. I just added “with multiple selections allowed” to the “choose from list” command. For some reason it didn’t seem to work before, but I see it does.

Thanks for the script, it works perfectly to remove one tag. But when I try to add “choose from list” to the command like this:


choose from list listTags with prompt {"Delete tag from \"" & name of current database & "\""} default items "" with multiple selections allowed

I can select multiple tags, but it doesn’t remove any tags on the selected files.
Any idea why?

Well this is very odd: I had thought that was the case at first, too (see above). But now I find it’s working fine. Are you using korm’s script, or mine? (I think it works with his, but not mine.)

I use korms script when I add this script snippet

Should work, then.

Won’t work just by adding “multiple selections allowed” – the loops need amending too. It’s simple, but can’t until maybe this weekend unless someone wants to fix it. :confused: Meanwhile, do one tag at a time.

But … it’s … working. I feel like we’re having a three-way dialogue of the deaf here.

Must be magic, then, because “multiple selections” don’t work here at all.

Weird weird weird. I’m telling you it works (here). And it works with the script that you posted. That’s why I thought you replied “Sure is.”