Changing group icons by script or rule?

Is there a way to programmatically modify the group icons?
I really like the mail group icon for threads but I don’t get it when I drag and drop mail into a group.
It would be great if there was a script or smart rule that would allow me to highlight groups and change their icon in one fell swoop.

I don’t see anything in the DT library in Script editor but there I am a foreigner reading signs in a language I sort of know,. I do see Icon functions in Finder scripting library but still…

This is a EENSY TEENSY point of friction but it helps with groups filled with all sorts of info per issue (PDFs and .txt. and elm etc.) that if all the emails were in a folder with an icon it would be a little easier to “read”.

  1. Add a PNG icon to the Global Inbox.
  2. Select it and choose Edit > Copy Item Link.
  3. Replace the item link in this code…
tell application id "DNtp"
	set emailIcon to (get record with uuid "x-devonthink-item://14E98595-A146-4E7F-BC7C-F973B30157BB") -- Item Link to a PNG file in the Global Inbox
	if emailIcon is not {} then
		set thumbnail of (selected records whose (type is group) and (type is not ordinary tag)) to (data of emailIcon)
	end if
end tell
  1. Select some groups and run the script.
    Done.
4 Likes

@BLUEFROG I have no need for this functionality at all, but the stuff you come up with is just fantastic!

1 Like

Nor do I have such a need but it was an interesting little puzzle with a tidy solution.
My hope is that people will see it and think, “Well, sheesh! That’s not even a long script at all. I might be able to do something like that!”

But I appreciate the kind words. :heart: :slight_smile:

2 Likes

One thing I do (for the very few indexed groups I have) is to change the group icon to the app icon that I usually use externally to DT. For example; my Bookmarks indexed attachments group has the bookmarks icon. That way I know it is indexed (yes it does have the DT index icon as well) and why it is indexed.

And just for a little extra learning, here is a slightly more verbose (and commented) option that actually could accommodate changing multiple attributes…

tell application id "DNtp"
	
	-- Item Link to a PNG file in the Global Inbox
	set emailIcon to (get record with uuid "x-devonthink-item://14E98595-A146-4E7F-BC7C-F973B30157BB")
	
	-- Do things only if the PNG is found
	if emailIcon is not {} then
		
		-- Isolate groups in the selection to avoid changing e.g., documents.
		set selectedGroups to (selected records whose (type is group) and (type is not ordinary tag))
		
		(* Loop through each group and set the thumbnail, one by one.
		A loop would be useful if you're modifying more attributes than the thumbnail, e.g., adding a tag, changing a rating, etc. *)
		repeat with theGroup in selectedGroups
			
			-- Set the thumbnail of the item in the repeat loop. Thumbnails are data or called by file paths
			set thumbnail of theGroup to (data of emailIcon)
		end repeat
		
	end if
end tell

As can be seen, it’s still not very long or hard to understand.

1 Like

I pondered the idea of automating this with a smart rule. Seems a bit excessive—I think a better approach is to make a project template that includes a group named “Emails”/“Correspondence” with the thumbnail already set.

But as an exercise, this smart rule works. Every time a group with the name “Email(s)” or “Correspondence” is created, or when a group is renamed to that, it gets the specified thumbnail.

on performSmartRule(theRecords)
	tell application id "DNtp"
		set emailIcon to (get record with uuid "x-devonthink-item://BC822DD0-134D-4866-98B8-6CD02BAC736B")
		if emailIcon is not {} then
			repeat with theRecord in theRecords
				set thumbnail of theRecord to (data of emailIcon)
			end repeat
		end if
	end tell
end performSmartRule

DT3’s icon for email groups as PNG:
Email-Group-512px.png.zip (274.6 KB)


My first idea was something like (simplified):

kind: email
on move, run script:
set thumbnail of (parent of theRecord) to emailIcon

But you wouldn’t want to change the thumbnail of every group you move an email into. I don’t know if it could make sense to limit parent in the script – simpler to just aim the smart rule at groups.

Date Added and On Import should be sufficient as you can’t modify the contents of an email nor can you create one. (And yes, On Demand should still be an option.)

I don’t follow. The screenshot is a smart rule that matches groups.

(My first hunch was also ultimately aimed at groups. But instead of matching groups, it would match emails. Move email to a group → automatically set the thumbnail of the parent group. But that doesn’t seem like a good idea.)