Searching for items containing the same Alias?


I’m integrating wiki links into my setup extensively, now that it has become possible to exclude certain items from wiki linking automatically through a smart rule.

So I’ve been adding lots of aliases as well, and beginning to think about how to efficiently manage long-term maintenance in regard to wiki links.

Is there a way to somehow figure out, which keywords or Aliases pertain to more than one item, and ideally to also show what these items are?

For example, I may have only a group “Agile Methods” for now, so it makes sense to add an Alias “Scrum” to this group. But at a later stage, I may create a summary of my notes on the Scrum method and therefore also add the “Scrum” alias to that summary, because I’m no longer aware it is already added to the Agile Methods folder.

Now there’s a duplicated Alias and I believe I read somewhere that the wiki link for “Scrum” would now randomly point to either of these items (pls correct me if I misunderstood this).

In any case, too maintain and optimize a Zettelkasten system using wiki links over time, I would love to find some way to identify these kinds of duplications as automatically as possible.

Does anyone have experience with this, or thoughts to share?

Use “aliases contains” plus the alias:


I doubt that there’s much to automate as you have to decide from which record you’d like to remove an alias.

I don’t think adding an alias of scrum to a file would be a worthwhile thing to do. An alias is not the same as a tag. An alias ideally functions like a nickname or alternate name, an aka.

For example, if you have a tag of National Aeronautics and Space Administration, you can add an alias of NASA. You could then type NASA in a tags field and it would resolve to the full tag.

Just something to consider.

Thanks for the input, @pete31 :slight_smile:

I am aware that it’s possible to find items with a specific alias. Also, I agree that certainly a “manual decision” is needed to figure out where the alias should best be used.

However, what I’m thinking of is a scenario where I am not aware that a certain alias has been used multiple times. So I’m looking for a way to find out, which aliases are currently being used in multiple items or groups across the database.

Then, once I know which aliases need to be reconsidered or corrected, I could use the search syntax to find the specific items in which one of them has been used. At this point, a decision can be made where the alias fits best.

Does that make sense?


Interesting, I think you’re right that it is possible to overdo the use of aliases.

Will keep this in mind; currently, I’m discovering how useful it is to get suggestions for related resources and insights as I am typing something. So definitely running that risk of adding too many :innocent:

You’re welcome.

And just as it is with people using aliases, if there’s more than one person using the same alias it’s much more difficult to determine who’s who.

Sure :slight_smile:

This Smart Rule script finds all records whose alias(es) are used in other record’s aliases and adds a tag.

It can be used as a normal script or as a Smart Rule script:

  • If used as normal script it acts on the current database.

  • If you want to use it in a Smart Rule set property theDatabaseName.


  • theDatabaseName: set database name
    Only necessary if you want to use it as Smart Rule script

  • considerCase: whether aliases should be compared case sensitive

  • theParentTag: name of the tag under which all other tags are grouped.
    The tag is created automatically

  • theTagSuffix: text that is added to the tag’s name

-- Tag records whose alias(es) are used in other record's aliases

property theDatabaseName : "" -- set database name (only necessary if you want to use it as Smart Rule script)
property considerCase : false -- whether aliases should be compared case sensitive
property theParentTag : "_Aliases Need Action" --  name of the tag under which all other tags are grouped. The tag is created automatically.
property theTagSuffix : "_AliasNeedsAction" -- text that is added to the tag's name

on run
	tell application id "DNtp"
		set theDatabaseName to name of current database
		my performSmartRule()
	end tell
end run

on performSmartRule()
	tell application id "DNtp"
			if considerCase = true then
				considering case
					my processAliases()
				end considering
				my processAliases()
			end if
		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
end performSmartRule

on processAliases()
	tell application id "DNtp"
			set theDatabase to database theDatabaseName
			set theDatabase_Aliases to aliases of contents of theDatabase whose aliases ≠ ""
			set theDatabase_Aliases_string to my tid(theDatabase_Aliases, ",")
			set theDatabase_Aliases_list to my tid(theDatabase_Aliases_string, {", ", "; ", ",", ";"})
			set theDatabase_Aliases_processed to {}
			repeat with thisAlias in theDatabase_Aliases_list
				set thisAlias to thisAlias as string
				if thisAlias is not in theDatabase_Aliases_processed then
					set theResults to search "aliases:~" & thisAlias in root of theDatabase
					set theResults_Count to (count theResults)
					if theResults_Count > 1 then
						set theResults_filterd to {}
						repeat with i from 1 to theResults_Count
							set thisRecord to item i of theResults
							set thisRecord_Aliases to my tid(aliases of thisRecord, {", ", "; ", ",", ";"})
							if thisRecord_Aliases contains thisAlias then set end of theResults_filterd to thisRecord
						end repeat
						set theResults_filterd_Count to (count theResults_filterd)
						if theResults_filterd_Count > 1 then
							repeat with i from 1 to theResults_filterd_Count
								set thisRecord to item i of theResults_filterd
								set tags of thisRecord to (tags of thisRecord) & {theParentTag & "/" & thisAlias & theTagSuffix}
							end repeat
						end if
					end if
				end if
				set end of theDatabase_Aliases_processed to thisAlias
			end repeat
		on error error_message number error_number
			if the error_number is not -128 then display alert "Error: Handler \"processAliases\"" message error_message as warning
			error number -128
		end try
	end tell
end processAliases

on tid(theInput, theDelimiter)
	set d to AppleScript's text item delimiters
	set AppleScript's text item delimiters to theDelimiter
	if class of theInput = text then
		set theOutput to text items of theInput
	else if class of theInput = list then
		set theOutput to theInput as text
	end if
	set AppleScript's text item delimiters to d
	return theOutput
end tid

Wow, it’s just incredible how you can come up with these scripts, @pete31! Really appreciate your help.

For anyone else wanting to use the script, these steps worked for me to set it up:

  1. Set the scope of the Smart Rule to all items, groups and tags
  2. Add the database name to the script where it says “set database name”
  3. Add script as “embedded script” to the Smart Rule and run it.
  4. Check the tag group “_Aliases Need Action”.

// edit: For further instructions, see Pete’s post below.


Ahh sorry. I forgot to add instructions.

Not sure I understand. There’s no need to do a search. All records with a given alias that’s not unique in the database are already searched and the tag shows the search’s result. You only need to remove the alias. I would probably

  • decide which record should keep the alias
  • remove it from record X
  • remove the tag from record X
  • repeat until only the record that should keep the alias is left
  • remove tag from record that should keep the alias
  • delete tag

But I didn’t test a whole workflow so I might be missing something.

Nope, I’m the one who missed something here :wink:

I didn’t comprehend that the script not only finds items that have duplicate aliases but also makes it unnecessary to search individually for the duplicated aliases in order to remove them.

So I now understand that the tag “Aliases need action” is actually a tag group, and it contains further tags in the format “SpecificDuplicatedAlias_Aliases need action”. Within each of these tags, all items contain the alias “SpecificDuplicatedAlias”, so all that needs to be done is to remove that alias (and the respective tag) from the items where it’s not needed.

This really is a beautiful solution! I will edit my previous post and refer to your instructions

It’s not necessary to create a Smart Rule if you want to run the script manually.

I’ve edited the script. It now can be used as normal script or as a Smart Rule script.

1 Like