Is it possible to script setting the record icon?

I have started to make a more intense use of icons to differentiate records, so my idea is to create prototypes (like one would in Tinderbox) and apply them via AppleScript. Is is possible?

I have no ideas about prototypes in Tinderbox, but yes you can set a thumbnail via AppleScript.

1 Like

Aha! Thanks a lot, Jim @BLUEFROG.
I kept looking for the term icon in the dictionary to no avail. :upside_down_face:

You’re welcome :slight_smile:

PS: the best option is to look at the properties of the element - in this case a record- in the dictionary first. There you can see all the properties available.

Thanks for the tip! That is indeed the best option! Script debugger even has a nice “Copy reference” feature :slight_smile:

By the way, were it not for you encouragement (many months ago) I would not have learned the first thing about Applescript. Now I love it :upside_down_face:

2 Likes

Thanks for the kind words and I’m glad to have helped along the way! :slight_smile:

I’m hoping to find more time for it again.


PS: If by protoype you mean template, note you can apply a custom thumbnail to a file and export it as a simple template. That icon should be preserved when you import the template.

image

Of course, for smart templates, the AppleScript can also come in handy.

1 Like

Same here :slight_smile:

I use this to set icons from a predefined list of icons or from a file.

-- Set record icon from list

property Item_1 : "Orange"
property item_1_path : "/Users/user/Library/Application Support/DEVONthink 3/DEVONthink 3 eigene Icons/Status Icons/DEVONthink 3 Group_orange.png"
property Item_2 : "Grün"
property item_2_path : "/Users/user/Library/Application Support/DEVONthink 3/DEVONthink 3 eigene Icons/Status Icons/DEVONthink 3 Group_green.png"
property Item_3 : "Rot"
property item_3_path : "/Users/user/Library/Application Support/DEVONthink 3/DEVONthink 3 eigene Icons/Status Icons/DEVONthink 3 Group_red.png"
property Item_4 : "Datei"

tell application "System Events" to set activeApp to name of first application process whose frontmost is true
tell application "SystemUIServer"
	activate
	set theChoice to choose from list {Item_1, Item_2, Item_3, Item_4} default items {Item_1} with title "DEVONthink Icon" with prompt "Icons setzen"
	if theChoice is false then return
end tell
activate application activeApp


if item 1 of theChoice = Item_1 then
	set thumb to POSIX file item_1_path as alias
	
else if item 1 of theChoice = Item_2 then
	set thumb to POSIX file item_2_path as alias
	
else if item 1 of theChoice = Item_3 then
	set thumb to POSIX file item_3_path as alias
	
else if item 1 of theChoice = Item_4 then
	set thumb to choose file of type {"jpg", "png", "tiff"} default location POSIX path of (path to pictures folder from user domain)
end if


tell application id "DNtp"
	try
		repeat with thisRecord in (selection as list)
			set thumbnail of thisRecord to (POSIX path of thumb)
		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
1 Like

Nice, @pete31! Thanks for sharing. I will give it a try. My solution so far had been to use a KM Macro to pass the variables (prototype name and icon) to the AppleScript, but yours look more economic.

You certainly did. You and Mr. Grunenberg (@cgrunenberg ). :wink:

Oh, by the way: I noticed something funny while setting the thumbnail via AppleScript. See the little white box around the icon? It always shows on the list view, but not in the inspector. If I copy and paste it again from the inspector, it disappears.

Sounds like a bug, we’ll check this.

The next release will fix this.

1 Like

@pete31 it’s been a while since you posted it, but thanks for the script!

Is there any chance that this could be transformed into a Smart Rule script?
I’m thinking along the lines of automatically changing icons e.g. based on a certain tag or other attribute.

No, as this script needs user interaction (and Smart Rule scripts run automatically).

This Smart Rule script sets a thumbnail. Should be easy to adjust it to your needs.


As you’re into customizing thumbnails you’ll probalby also want to take a look at Script: Colorize DEVONthink Icons (Color Code Magick).

For me it’s one of the most useful scripts as it makes finding groups (e.g. in the navigation sidebar) a lot faster. Instead of searching for the name it’s just one look and I know “Ah, this is what I want”.

Wow, the script in your first link is exactly what I was looking for! Thank you!

Set it up with a SmartRule after changing the code to link to a local icon file and it’s working perfectly.

The second script also looks really interesting but seems to need a bit more setup. Will bookmark it for the next iteration of optimizing icons, sometime in the future :wink:

1 Like