Changing tag names and smart group rules

I have been setting up a lot of smart groups that search for specific tags. Then I change the tag name for various reasons, and the smart group no longer works because it is searching for a tag that no longer exists. Is there any way to automatically update the tag name everywhere it is used, including in smart group rules? Is there a unique item ID associated with the tag that I could somehow use in the smart group that would achieve this desired behavior? I would like the smart group rules to update to the new tag name. Thank you

If you’re talking about global smart rules, then the answer is no.

I am not talking about smart rules, but saved searches (smart groups), which live in a single database

Slip of the mind :slight_smile:

but saved searches (smart groups), which live in a single database

Those are called local smart groups.

And are you referring to your very complicated smart groups?

Generally, yes, they are complicated smart groups. They have a bunch of title search terms as well as a tag search

Then I change the tag name for various reasons, and the smart group no longer works because it is searching for a tag that no longer exists

Changing a tag changes it on every item it’s applied to. But DEVONthink is not going to magically locate and change your smart groups as well. At a minimum, you need to locate the ones that need changing.

PS: If you are going to be changing tags like this often, perhaps you need to examine your process. It seems quite fragile to be broken by such a simple change.

That being said, it is possible to change a local smart group’s predicates though it requires scripting and filtering the criteria to accomplish.

Before

After

You could think about moving the creation of those smart rules into an AppleScript/JXA script. Mass changes to those scripts should be a lot easier given an “almighty” editor at hand.

Process for database local smart groups could be:

  1. Change scripts
  2. Remove old smart groups
  3. Run script to create new smart groups

Example for one of my scripts I use within my templates:

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

tell application id "DNtp"
	activate
	
	-- get record
	local theWindow
	set theWindow to think window 1
	
	local theRecords
	set theRecords to (selection of theWindow)
	
	local theRecord
	set theRecord to (item 1 of theRecords)
	
	-- run code
	local currentYear
	set currentYear to year of (current date)
	
	local theResult
	set theResult to display dialog "Please fill in the tax year you want to create the group structure" default answer currentYear
	
	local taxYear
	set taxYear to text returned of theResult
	
	set name of theRecord to "fuer_" & taxYear
	
	-- check on subgroup
	local relevantGroup
	set relevantGroup to get record at (location with name of newGroup & "/unterlagen/relevant")
	
	if relevantGroup is missing value then
		error "Record could not be found at " & quoted form of (location with name of theRecord & "/Eingereichte Unterlagen")
	end if
	
	create record with {name:"Alle PDF Dokumente", record type:smart group, search predicates:"kind:pdf", search group:relevantGroup} in newGroup
	
	set allTaxDocsGroup to create record with {name:"Alle Steuerunterlagen fĂĽr " & taxYear, record type:smart group, search predicates:"kind:pdf {any: tags:taxes-" & taxYear & ";steuern-" & taxYear & "}"} in newGroup
	set search group of allTaxDocsGroup to (get record at "/")
end tell

The following code could be handy to reference an existing group - if works for both scenarios existing/missing group.

		local scriptsGroup
		set scriptsGroup to create location nameNewGroup in theGroup
1 Like