Is it possible to script the color of tags?


since I use tags a lot, I find it quite useful to set color coding for different types of tags in my database.

Is it possible to use smart rules in order to automate this for newly tagged items?


E.g. like this to set the color to red:

tell application id "DNtp" to set color of selected records to {65535, 0, 0}
1 Like

Thank you for such a quick response @cgrunenberg.

I tried to translate this into code for a smart rule, but it’s not working yet. Are there any obvious issues with the following script?

edit: script is now updated and fully functional based on Pete’s advice below.

on performSmartRule(theRecords)
	tell application id "DNtp"
			repeat with theRecord in theRecords
				set color of theRecord to {51914, 37779, 20303}
			end repeat
		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

To specify the issue I’m seeing:
The new color (red) is only applied to one of the tags in scope for the smart rule I’m testing with. The second tag, which is nested under the first, doesn’t receive the new color (see screenshot).

Screenshot 2022-04-08 at 09.41.35

Take a look at this line repeat with theRecord in theRecords.

The variable that comes after repeat with must be used inside the repeat to access the item that’s currently processed in the repeat.

So, in the repeat, replace selected records with theRecord.


That solved it! Much appreciated @pete31 :+1:

For anyone wanting to use the same script: The color codes like e.g. {51914, 37779, 20303} are set by using RGB values and multiplying each with 257. This is apparently because AppleScript requires 16-bit values rather than standard RGB - at least that is my understanding.

1 Like

I’m curious how you’re using this smart rule.

Items in my database are categorized on three “dimensions”: Item Type, Topic and Author/Source. I am using group tags for this, as the tags filter allows me to quickly filter e.g. all items under a certain author to only show non-fiction books while retaining the hierarchy (unlike using search).

As a side effect of the nested hierarchy in each dimension there are a lot of tags for each item, of which the most specific ones (i.e. lowest level of the hierarchy) are by far the most relevant.

The smart rules (there are multiple now) achieve the following:
a) Visually distinguish tags in each dimension from each other (i.e. authors are orange, topics blue etc.)
b) Visually distinguish the most specific/relevant tags (e.g. darker blue) from the less specific inherited parent tags.
c) Mark other tags I use e.g. for maintenance in a neutral color so as to “fade into the background” a bit

Here’s a screenshot. Still a bit cluttered but way more readable if one knows what the colors mean.

Screenshot 2022-04-08 at 16.55.05

Side tangent:
I also have a smart rule that adds a “_” character to the lowest-level tags so that they are shown in the front. The ideal solution regarding the order, however, would still be a hierarchical order from my perspective. Or perhaps a preference allowing users to only show tags that have been directly applied to an item in the inspector.


If it makes sense to you, have at it. :slight_smile:

Amazing how many unique ways there are to use DT3 to organize information.