Change file icon via AppleScript?

Hello,

I am looking for a way to set the Icon of a file in AppleScript (unfortunately it does not work to select multiple files and then paste an icon in the Info window to all of them at once). I did not find anything in DTP’s AppleScript Library. Any hint?

Background:
I would like to use the icon as an additional visual clue to spot files with a certain content within long file lists of text-files. Example: My database holds information on characters, places, scene outline, comments and the draft chapters. So a search usually brings up lot of text files covering every of these aspects. Scanning the result and spotting the relevant one would be much easier for me if those files would have different Icons based on the aspect (Character, Place, Scene, draft …).
And I want this in addition to labels as I use labels for temporary flagging.

Johannes

This should be possible by setting the thumbnail of a record, e.g.

set thumbnail of myRecord to “/path/of/the/icon/to/use”

Thank you, that works great.
What is your recommendation for size, resolution and format? I don’t want to waste disk-space or slow DTP down with resizing. I only need a small list icon.

Johannes

Maximal size is 256x256, larger images are scaled. If the image doesn’t have an alpha channel, then it’s stored as a JPEG (using less space) internally, otherwise as a loseless TIFF (using more space).

Note: Using the same icon several times doesn’t waste additional space, the icon is only stored once.

That’s good news.

Thank you for your kind and quick response.

Johannes

For those who might be interested in my icon scripts see the example below.

The script loops through the selected records and sets the icon (thumbnail) to one of three images. If the record is a group it gets the CharacterGroup.png, if it is plain text or rtf it gets either Character.png (if the comment of the record is “Character”) or CharacterNote.png. All other types (like link, pdf, images) don’t get a new icon with this script.

I think you get the idea. Tailor the script to your needs.

I placed the icon files within DTP itself. if you like them elsewhere you have to modifiy the varibale cPath.

I have similar scripts (and icons) for places, regions and groups with shortcuts. So a simple keystroke will set the right icon.

This is how my search result looks like with some new icons instead of the generic icons giving an instant visual clue, what these record are about:
net-artworks.de/Images/DTPwithIcons.png
(sorry I am no icon designer)

As Christian pointed out: using those icons will not blow up you database. Each icon is only stored once.

Johannes

using terms from application "DEVONthink Pro"
	tell application "DEVONthink Pro"
		try
			if not (exists think window 1) then error "No window is open."
			set cPath to (path of current database) & "/Files/"
			--display dialog cPath
			set this_selection to the selection
			--if (count of theSelection) is not 1 then error "Please select one content."
			repeat with this_item in this_selection
				set cType to type of this_item as string
				set cComment to comment of this_item as string
				if cType is "group" then
					set thumbnail of this_item to cPath & "CharacterGroup.png"
				else if (cType is "text" or cType is "rtf") then
					if (cComment is "Character") then
						set thumbnail of this_item to cPath & "Character.png"
					else
						set thumbnail of this_item to cPath & "CharacterNote.png"
					end if
				end if
			end repeat
		on error error_message number error_number
			if the error_number is not -128 then
				try
					display alert "DEVONthink Pro" message error_message as warning
				on error number error_number
					if error_number is -1708 then display dialog error_message buttons {"OK"} default button 1
				end try
			end if
		end try
	end tell
end using terms from