Script: Colorize DEVONthink Icons (Color Code Magick)

This is Color Code Magick.

Create colorized DEVONthink icons (via ImageMagick) and use lots of options that make finding your preferred custom icons easier.

Here are some randomly created colors

Once you’ve found some nice ones and added them to your list you can disable some or all options that are mainly useful during setup. You don’t have to bookmark colors, the script can be used with the color picker all the time but that soon leads to a quite distracting UI.

Simplest way to use the same color again without having bookmarked it is selecting a record with a colorized icon and those you like to apply this color to. The record type doesn’t matter, the script automagically sets the right icon.

To bookmark a color simply add your description wrapped in underscores to the filename

	40.194.70.Thumb_Group_I like this color_ 

The list is sorted alphabetically, you can change the order like this

	40.194.70.Thumb_Group_I like this color_01_ 

Note the underscore at the end.

There’s an option to create preview records for all icons you’ve created which makes it easy to compare icons right inside DEVONthink. Make sure to delete this group afterwards, otherwise it can get quite confusing if you’ve deleted unused files (there’s an option for that) since the last time you’ve used the preview option.

I added an option to create custom database icons but removed it as the results were unsatisfying due to the small PNG file DEVONthink uses. Would be great if we could get a real database icon.

Here’s a demo (bad quality, my first gif …)

Setup

Install ImageMagick, I used Homebrew.

In the Color Code Magick setup script set a foldername, a path and the path to your ImageMagick installation (run “which magick” in Terminal.app).

In the main script paste the path you’ve set in the setup script, set the ImageMagick path and have fun.

Color Code Magick script

-- Color Code Magick
-- Set colorized DEVONthink icons respecting the record type

property deleteOverwriteAll : false -- prevent loos of existing thumbnails
property useChooseFromList : true -- access your default colors and more
property useMenuMaintenanceMode : true -- easy access during setup  
property useMenuColorPicker : true
property useMenuRevealFile : true
property useMenuRevealDefaultColors : true
property useMenuDeleteUnusedFiles : true
property useMenuCreatePreviewRecords : true
property useMenuRevealNonMagick : true
property menuRemove : "Thumbnail entfernen"
property menuColorPicker : "Farbauswähler nutzen"
property menuRevealFile : "Dateien der Auswahl anzeigen"
property menuRevealDefaultColors : "Standardfarben anzeigen"
property menuDeleteUnusedFiles : "Nicht verwendete Farben entfernen"
property menuCreatePreviewRecords : "Vorschau für alle Farben erstellen"
property menuRevealNonMagick : "Nicht-Magick-Thumbnails anzeigen"
property menuEnterMaintenance : "Weitere Optionen anzeigen"
property defaultColorPickerColor : {38550, 49344, 24672}
property chooseFromListTitle : ""

property imageMagickPath : "" -- run "which magick" in Terminal to get the path (e.g. /usr/local/bin/magick)
property theMagickFolderPath : "" -- paste here
property theMagickFolderHFSPath : POSIX file (theMagickFolderPath & "Thumbnail PNGs/") as string

tell application "System Events"
	try
		exists POSIX file ((theMagickFolderPath & "Thumbnail PNGs/Magick Thumbnails.plist") as string) as alias
	on error
		make new property list file with properties {name:(theMagickFolderPath & "Thumbnail PNGs/Magick Thumbnails.plist") as string}
	end try
end tell

tell application id "DNtp"
	try
		set windowClass to class of think window 1
		if windowClass = viewer window then
			set theRecords to selection of window 1
		else if windowClass = document window then
			set theRecords to {content record of window 1}
		end if
		if theRecords = {} then error "Nichts ausgewählt."
		
		set theColors to {}
		set withoutThumbnail to {}
		set withMagickThumbnail to {}
		set withNonMagickThumbnail to {}
		repeat with thisRecord in theRecords
			using terms from scripting additions
				set thisRecord to contents of thisRecord
			end using terms from
			try
				thumbnail of thisRecord as anything
				try
					set thisColor to my readPlist(my getUUID(thisRecord))
					if thisColor ≠ "" then
						if theColors does not contain thisColor then set end of theColors to thisColor
						set end of withMagickThumbnail to thisRecord
					else
						set end of withNonMagickThumbnail to thisRecord
					end if
				end try
			on error
				set end of withoutThumbnail to thisRecord
			end try
		end repeat
		
		if deleteOverwriteAll = true then set withoutThumbnail to withoutThumbnail & withNonMagickThumbnail
		set countwithMagickThumbnail to (count withMagickThumbnail)
		
		-- countwithMagickThumbnail = 0
		
		if countwithMagickThumbnail = 0 then
			if (count withoutThumbnail) > 0 then
				if useChooseFromList = true then
					my chooseFromList(withoutThumbnail)
				else
					set {R, G, B} to my colorPicker()
					my existsThumbnailType(withoutThumbnail, R, G, B)
				end if
			else
				display alert "Hoppla!" buttons {"", "Ok"} default button 2 message "Auswahl enthält kein Magick-Thumbnail."
			end if
			
			-- countwithMagickThumbnail = 1 
			
		else if countwithMagickThumbnail = 1 then
			if (count withoutThumbnail) = 0 then
				my chooseFromList(withMagickThumbnail)
			else
				set {R, G, B} to {item 1, item 2, item 3} of my textItemDelimiters(item 1 of theColors, ".")
				my existsThumbnailType(withoutThumbnail, R, G, B)
			end if
			
			-- countwithMagickThumbnail > 1
			
		else if countwithMagickThumbnail > 1 then
			if (count withoutThumbnail) = 0 then
				my chooseFromList(withMagickThumbnail)
			else
				if (count theColors) ≤ 1 then
					set {R, G, B} to {item 1, item 2, item 3} of my textItemDelimiters(item 1 of theColors, ".")
					my existsThumbnailType(withoutThumbnail, R, G, B)
				else
					set theAlert to display alert "Hoppla!" buttons {"Beenden", "Zeige Optionen"} default button 2 message "Auswahl enthält verschiedene Farben." as informational
					if button returned of theAlert = "Zeige Optionen" then my chooseFromList(withoutThumbnail & withMagickThumbnail)
				end if
			end if
		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

on existsThumbnailType(theRecords, R, G, B)
	try
		set createTheseTypes to {}
		set theIconName to ""
		repeat with thisRecord in theRecords
			set iconName to my recordType(thisRecord)
			if iconName ≠ theIconName then if my pathsContaining((R & "." & G & "." & B & "." & "Thumb_" & iconName) as string) = {} then set end of createTheseTypes to iconName
			set theIconName to iconName
		end repeat
		if createTheseTypes ≠ {} then
			my createTempRecords(createTheseTypes, R, G, B, theRecords)
		else
			my setThumbnail(theRecords, R, G, B)
		end if
	on error error_message number error_number
		if the error_number is not -128 then display alert "Handler \"existsThumbnailType\"" message error_message as warning
	end try
end existsThumbnailType

on chooseFromList(theRecords)
	local menuRevealFile
	try
		tell application "System Events" to set defaultPaths to POSIX path of (files of folder theMagickFolderHFSPath whose name ends with "_.png")
		if defaultPaths ≠ {} then
			set thePrefixedPaths to {}
			repeat with thisPath in defaultPaths
				try
					(character -6 in thisPath) as number
					set end of thePrefixedPaths to (characters -7 thru -6 in thisPath & thisPath) as string
				on error
					set end of thePrefixedPaths to "XX" & thisPath as string
				end try
			end repeat
			set sortedPrefixedPaths to my sort_list(thePrefixedPaths)
			set sortedPaths to {}
			repeat with thisPath in sortedPrefixedPaths
				set end of sortedPaths to characters 3 thru -1 in thisPath as string
			end repeat
			set {defaultColorNames, theColors} to {{}, {}}
			repeat with thisPath in sortedPaths
				set theFileName to (characters ((length of (theMagickFolderPath & "Thumbnail PNGs/") as string) + 1) thru -1 in thisPath) as string
				set end of defaultColorNames to item 3 of my textItemDelimiters(theFileName, "_")
				set {R, G, B} to {item 1, item 2, item 3} of my textItemDelimiters(theFileName, ".")
				set end of theColors to {red:R, green:G, blue:B}
			end repeat
		else
			set defaultColorNames to {"-- Keine Standardfarben gefunden --"}
		end if
		
		set menuItems to defaultColorNames
		if useMenuColorPicker = true then set menuItems to menuItems & {menuColorPicker}
		set menuItems_Maintenance to {}
		if useMenuRevealFile = true then
			if my withMagickThumbnail ≠ {} then
				set menuRevealFile to my menuRevealFile
			else
				set menuRevealFile to "Ordner öffnen"
			end if
			set menuItems_Maintenance to menuItems_Maintenance & {menuRevealFile}
		else
			set menuRevealFile to my menuRevealFile
		end if
		if useMenuRevealDefaultColors = true then set menuItems_Maintenance to menuItems_Maintenance & {menuRevealDefaultColors}
		if useMenuCreatePreviewRecords = true then set menuItems_Maintenance to menuItems_Maintenance & {menuCreatePreviewRecords}
		if useMenuDeleteUnusedFiles = true then set menuItems_Maintenance to menuItems_Maintenance & {menuDeleteUnusedFiles}
		if my withNonMagickThumbnail ≠ {} then if useMenuRevealNonMagick = true then if my windowClass as string = "viewer window" then set menuItems_Maintenance to menuItems_Maintenance & {menuRevealNonMagick}
		if useMenuMaintenanceMode = true then
			set menuItems to menuItems & menuItems_Maintenance
		else
			if menuItems_Maintenance ≠ {} then set menuItems to menuItems & {menuEnterMaintenance}
		end if
		if my countwithMagickThumbnail > 0 then set menuItems to {menuRemove} & menuItems
		
		tell application id "DNtp" to set theChoice to choose from list menuItems default items {item 1 of menuItems} with prompt "" with title chooseFromListTitle
		if theChoice is false then return
		set theChoice_item1 to item 1 of theChoice
		if theChoice_item1 = menuRemove then
			my deleteThumbnail(theRecords)
		else if theChoice_item1 is "-- Keine Standardfarben gefunden --" then
			my revealFile({})
		else if theChoice_item1 = menuColorPicker then
			set {R, G, B} to my colorPicker()
			my existsThumbnailType(theRecords, R, G, B)
		else if theChoice_item1 = menuRevealFile then
			if my countwithMagickThumbnail = 0 then set theRecords to {}
			my revealFile(theRecords)
		else if theChoice_item1 = menuRevealDefaultColors then
			my revealDefaultColors(defaultPaths)
		else if theChoice_item1 = menuCreatePreviewRecords then
			my createPreview()
		else if theChoice_item1 = menuDeleteUnusedFiles then
			my deleteUnusedFiles(defaultPaths)
		else if theChoice_item1 = menuRevealNonMagick then
			tell application id "DNtp" to set selection of think window 1 to my withNonMagickThumbnail
		else if theChoice_item1 = menuEnterMaintenance then
			set menuItems to menuItems_Maintenance
			tell application id "DNtp" to set theChoice to choose from list menuItems default items (item 1 of menuItems) with prompt "" with title chooseFromListTitle
			if theChoice is false then return
			set theChoice_item1 to item 1 of theChoice
			if theChoice_item1 = menuRevealFile then
				if my countwithMagickThumbnail = 0 then set theRecords to {}
				my revealFile(theRecords)
			else if theChoice_item1 = menuRevealDefaultColors then
				my revealDefaultColors(defaultPaths)
			else if theChoice_item1 = menuDeleteUnusedFiles then
				my deleteUnusedFiles(defaultPaths)
			else if theChoice_item1 = menuCreatePreviewRecords then
				my createPreview()
			else if theChoice_item1 = menuRevealNonMagick then
				tell application id "DNtp" to set selection of think window 1 to my withNonMagickThumbnail
			end if
		else
			set {R, G, B} to {red, green, blue} of (item (my list_position(theChoice_item1, defaultColorNames))) of theColors
			my existsThumbnailType(theRecords, R, G, B)
		end if
	on error error_message number error_number
		if the error_number is not -128 then display alert "Handler \"chooseFromList\"" message error_message as warning
	end try
end chooseFromList

on createTempRecords(createTheseTypes, R, G, B, theRecords)
	try
		tell application id "DNtp"
			set theTempGroup to create location "/thumbnail magick [temp]/" in inbox
			set theTempRecords to {}
			if createTheseTypes contains "Group" then set theTempRecords to theTempRecords & {(create record with {type:group} in theTempGroup)}
			if createTheseTypes contains "Inbox" then set theTempRecords to theTempRecords & {(create record with {type:group, name:"magick_temp_Inbox"} in theTempGroup)}
			if createTheseTypes contains "dtRecord" then set theTempRecords to theTempRecords & {(create record with {type:bookmark} in theTempGroup)}
			if createTheseTypes contains "RSS" then set theTempRecords to theTempRecords & {(create record with {type:feed} in theTempGroup)}
			if createTheseTypes contains "Smart-Date" then set theTempRecords to theTempRecords & {(create record with {type:smart group, search predicates:"additionDate:This Hour"} in theTempGroup)}
			if createTheseTypes contains "Smart-Group" then set theTempRecords to theTempRecords & {(create record with {type:smart group, search predicates:"name:magick"} in theTempGroup)}
			if createTheseTypes contains "Tag" then set theTempRecords to theTempRecords & {(create location "/Tags/..thumbnail magick_temp" in inbox)}
			if createTheseTypes contains "Twitter" then set theTempRecords to theTempRecords & {(create record with {type:feed, URL:"feed://twitter.com/"} in theTempGroup)}
			repeat with thisTempRecord in theTempRecords
				set iconName to my recordType(thisTempRecord)
				set thisOutputPath to (theMagickFolderPath & "Thumbnail PNGs/" & R & "." & G & "." & B & "." & "PNG_" & iconName & ".png") as string
				do shell script imageMagickPath & space & quoted form of ((theMagickFolderPath & "Icon PNGs/" & iconName & ".png") as string) & " -fill 'rgb(" & R & "," & G & "," & B & ")' -colorize 100 " & quoted form of thisOutputPath
				set thumbnail of thisTempRecord to thisOutputPath
				repeat 25 times
					set thisThumbnail to thumbnail of thisTempRecord
					try
						set thisThumbnail to thisThumbnail
						exit repeat
					on error
						delay 0.1
					end try
				end repeat
				my write_to_file(thumbnail of thisTempRecord, (theMagickFolderPath & "Thumbnail PNGs/" & R & "." & G & "." & B & "." & "Thumb_" & iconName & ".png") as string)
				tell application "Finder" to set extension hidden of file (POSIX file ((theMagickFolderPath & "Thumbnail PNGs/" & R & "." & G & "." & B & "." & "Thumb_" & iconName & ".png") as string) as alias) to true
				delete record thisTempRecord
			end repeat
			my setThumbnail(theRecords, R, G, B)
			tell application "System Events" to delete (files of folder theMagickFolderHFSPath whose name starts with ((R & "." & G & "." & B & "." & "PNG_") as string))
			delete record theTempGroup
		end tell
	on error error_message number error_number
		if the error_number is not -128 then display alert "Handler \"createTempRecords\"" message error_message as warning
	end try
end createTempRecords

on setThumbnail(theRecords, R, G, B)
	try
		tell application id "DNtp"
			set theIconName to ""
			repeat with thisRecord in theRecords
				set iconName to my recordType(thisRecord)
				if iconName ≠ theIconName then
					set theFilePath to item 1 of my pathsContaining((R & "." & G & "." & B & "." & "Thumb_" & iconName) as string)
				end if
				set thumbnail of thisRecord to theFilePath
				set theIconName to iconName
				my writePlist(my getUUID(thisRecord), (R & "." & G & "." & B) as string)
			end repeat
		end tell
	on error error_message number error_number
		if the error_number is not -128 then display alert "Handler \"setThumbnail\"" message error_message as warning
	end try
end setThumbnail

on deleteThumbnail(theRecords)
	try
		tell application id "DNtp"
			set theUUIDs to {}
			repeat with thisRecord in theRecords
				set iconName to my recordType(thisRecord)
					set theUUID to my getUUID(thisRecord)
					if deleteOverwriteAll = true then
						delete thumbnail of thisRecord
						set end of theUUIDs to theUUID
					else
						if my readPlist(theUUID) ≠ "" then
							delete thumbnail of thisRecord
							set end of theUUIDs to theUUID
						end if
					end if
			end repeat
		end tell
		repeat with thisUUID in theUUIDs
			try
				do shell script "plutil -remove " & quoted form of thisUUID & space & quoted form of ((theMagickFolderPath & "Thumbnail PNGs/Magick Thumbnails.plist") as string)
			end try
		end repeat
	on error error_message number error_number
		if the error_number is not -128 then display alert "Handler \"deleteThumbnail\"" message error_message as warning
	end try
end deleteThumbnail

on pathsContaining(theString)
	try
		tell application "System Events" to set theThumbnailPaths to POSIX path of (files of folder theMagickFolderHFSPath whose name contains theString)
	on error error_message number error_number
		if the error_number is not -128 then display alert "Handler \"pathsContaining\"" message error_message as warning
	end try
end pathsContaining

on openFolder(theText)
	tell application id "DNtp" to set theAlert to display alert "Hoppla!" buttons {"Ok", "Ordner öffnen"} default button 2 message theText as informational
	if button returned of theAlert = "Ordner öffnen" then my revealFile({})
end openFolder

on colorPicker()
	tell application id "DNtp" to set theColor to (choose color default color defaultColorPickerColor)
	set R to round ((item 1 of theColor) / 257) rounding to nearest
	set G to round ((item 2 of theColor) / 257) rounding to nearest
	set B to round ((item 3 of theColor) / 257) rounding to nearest
	return {R, G, B}
end colorPicker

on getUUID(theRecord)
	tell application id "DNtp"
		set theRefURL to reference URL of theRecord
		set theUUID to (characters 21 thru -1 in theRefURL) as string
	end tell
end getUUID

on writePlist(theUUID, theColor)
	try
		tell application "System Events"
			tell property list file ((theMagickFolderPath & "Thumbnail PNGs/Magick Thumbnails.plist") as string)
				if exists property list item theUUID then
					set value of property list item theUUID to theColor
				else
					make new property list item at end of property list items of contents with properties {kind:string, name:theUUID, value:theColor}
				end if
			end tell
		end tell
	on error error_message number error_number
		if the error_number is not -128 then display alert "Handler \"writePlist\"" message error_message as warning
	end try
end writePlist

on readPlist(theUUID)
	try
		tell application "System Events"
			tell property list file ((theMagickFolderPath & "Thumbnail PNGs/Magick Thumbnails.plist") as string)
				try
					set theColor to value of property list item theUUID
				on error
					set theColor to ""
				end try
			end tell
		end tell
	on error error_message number error_number
		if the error_number is not -128 then display alert "Handler \"readPlist\"" message error_message as warning
	end try
end readPlist

on revealFile(theRecords)
	try
		tell application "Finder"
			if theRecords ≠ {} then
				set theFiles to {}
				repeat with thisRecord in theRecords
					try
						set thisColor to my readPlist(my getUUID(thisRecord))
						if thisColor ≠ "" then set end of theFiles to file (POSIX file (item 1 of my pathsContaining((thisColor & ".Thumb_" & my recordType(thisRecord)) as string) as string) as alias)
					end try
				end repeat
				#activate
				open folder (POSIX file ((theMagickFolderPath & "Thumbnail PNGs/") as string) as alias)
				set selection to {}
				reveal theFiles
				activate
			else
				#activate
				open folder (POSIX file ((theMagickFolderPath & "Thumbnail PNGs/") as string) as alias)
				set selection to {}
				activate
			end if
		end tell
	on error error_message number error_number
		if the error_number is not -128 then display alert "Handler \"revealFile\"" message error_message as warning
	end try
end revealFile

on revealDefaultColors(defaultPaths)
	try
		if defaultPaths ≠ {} then
			tell application "Finder"
				set theFiles to {}
				repeat with thisPath in defaultPaths
					set end of theFiles to file (POSIX file (thisPath as string) as alias)
				end repeat
				open folder (POSIX file ((theMagickFolderPath & "Thumbnail PNGs/") as string) as alias)
				set selection to {}
				reveal theFiles
				activate
			end tell
		else
			my openFolder("Keine Standardfarben gefunden." & return & "Füge dem Dateinamen z.B. \"_Grün_\" hinzu.")
		end if
	on error error_message number error_number
		if the error_number is not -128 then display alert "Handler \"revealDefaultColors\"" message error_message as warning
	end try
end revealDefaultColors

on deleteUnusedFiles(defaultPaths)
	try
		tell application "System Events"
			set allPaths to POSIX path of (files of folder theMagickFolderHFSPath whose name does not end with ".plist" and visible is true)
			if allPaths ≠ {} then
				set defaultColors to {}
				repeat with thisPath in defaultPaths
					set end of defaultColors to (characters ((length of (theMagickFolderPath & "Thumbnail PNGs/") as string) + 1) thru ((offset of ".Thumb" in thisPath) - 1) in thisPath) as string
				end repeat
				set usedColors to defaultColors
				tell property list file ((theMagickFolderPath & "Thumbnail PNGs/Magick Thumbnails.plist") as string)
					repeat with i in property list items
						set thisColor to value of i
						if usedColors does not contain thisColor then set end of usedColors to thisColor
					end repeat
				end tell
				repeat with thisPath in allPaths
					set deleteThisPath to true
					repeat with thisColor in usedColors
						if thisPath contains thisColor then
							set deleteThisPath to false
							exit repeat
						end if
					end repeat
					if deleteThisPath = true then delete file thisPath
				end repeat
			end if
		end tell
	on error error_message number error_number
		if the error_number is not -128 then display alert "Handler \"deleteUnusedFiles\"" message error_message as warning
	end try
end deleteUnusedFiles

on createPreview()
	try
		tell application "System Events" to set allPaths to POSIX path of (files of folder theMagickFolderHFSPath whose name does not end with ".plist" and visible is true)
		if allPaths ≠ {} then
			tell application id "DNtp"
				set theGroup to create location "/_magick thumbnail preview" in inbox
				repeat with thisPath in allPaths
					set thisColor to (characters ((length of (theMagickFolderPath & "Thumbnail PNGs/") as string) + 1) thru ((offset of ".Thumb" in thisPath) - 1) in thisPath) as string
					create record with {type:group, name:thisColor, thumbnail:thisPath} in theGroup
				end repeat
				open window for record theGroup
				activate
			end tell
		else
			my openFolder("Keine Dateien gefunden")
		end if
	on error error_message number error_number
		if the error_number is not -128 then display alert "Handler \"createPreview\"" message error_message as warning
	end try
end createPreview

on recordType(theRecord)
	try
		tell application id "DNtp"
			set theType to type of theRecord as string
			if theType = "«constant ****DTgr»" or theType = "group" then
				set theName to name of theRecord
				if kind of theRecord = "Tag" or (location of theRecord & theName) as string = "/Tags" then
					set iconName to "Tag"
				else if reference URL of theRecord = reference URL of incoming group of database of theRecord or theName = "magick_temp_Inbox" then
					set iconName to "Inbox"
				else
					set iconName to "Group"
				end if
			else if theType = "«constant ****DTsg»" or theType = "smart group" then
				set iconName to "Smart-Group"
				set searchPredicates to search predicates of theRecord
				repeat with thisWord in (words of searchPredicates)
					if thisWord is in {"additionDate", "creationDate", "dueDate", "modificationDate", "openingDate"} then
						set iconName to "Smart-Date"
						exit repeat
					end if
				end repeat
			else if theType = "«constant ****feed»" or theType = "feed" then
				set iconName to "RSS"
				if URL of theRecord starts with "feed://twitter.com/" then set iconName to "Twitter"
			else
				set iconName to "dtRecord"
			end if
			return iconName
		end tell
	on error error_message number error_number
		if the error_number is not -128 then display alert "Handler \"recordType\"" message error_message as warning
	end try
end recordType

on textItemDelimiters(theText, theDelimiter)
	set d to AppleScript's text item delimiters
	set AppleScript's text item delimiters to theDelimiter
	set TextItems to text items of theText
	set AppleScript's text item delimiters to d
	return TextItems
end textItemDelimiters

on sort_list(theList)
	set old_delims to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {ASCII character 10}
	set list_string to (theList as string)
	set new_string to do shell script "echo " & quoted form of list_string & " | sort -f"
	set new_list to (paragraphs of new_string)
	set AppleScript's text item delimiters to old_delims
	return new_list
end sort_list

on list_position(this_item, this_list)
	repeat with i from 1 to the count of this_list
		if item i of this_list is this_item then return i
	end repeat
	return 0
end list_position

on write_to_file(this_data, target_file)
	try
		set the target_file to the target_file as text
		set the open_target_file to open for access POSIX file target_file with write permission
		set eof of the open_target_file to 0
		write this_data to the open_target_file starting at eof
		close access the open_target_file
		return true
	on error
		try
			close access POSIX file target_file
		end try
		return false
	end try
end write_to_file

Setup script

-- Color Code Magick Setup

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

property imageMagickPath : "" -- run "which magick" in Terminal to get the path (e.g. /usr/local/bin/magick)
property folderName : "" -- e.g. "Color Code Magick [Custom DEVONthink Icons]"
property customPath : "" -- e.g. "/Users/username/". If customPath = "" then pictures folder is used (no good idea, PNGs will be in search results)

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

tell application "System Events"
	try
		exists POSIX file imageMagickPath as alias
	on error
		display alert "Hoppla!" buttons {"Beenden", "Ok"} default button 2 message "Image Magick nicht unter diesem Pfad gefunden." as critical
		return
	end try
end tell

if customPath = "" then
	set thePath to POSIX path of (path to pictures folder from user domain)
else
	set thePath to customPath
	if thePath does not end with "/" then set thePath to (thePath & "/") as string
end if

set theMagickFolderPath to (thePath & folderName & "/") as string
do shell script "mkdir -p " & quoted form of (theMagickFolderPath & "Icon PNGs") as string
do shell script "mkdir -p " & quoted form of (theMagickFolderPath & "Thumbnail PNGs") as string

set theResourcesPath to ((POSIX path of (path to application id "DNtp") as text) & "/Contents/Resources/") as string

repeat with thisIcon in {"dtRecord.icns", "Group.icns", "Inbox.icns", "RSS.icns", "Smart-Date.icns", "Smart-Group.icns", "Tag.icns", "Twitter.icns"}
	set thePNGPath to (theMagickFolderPath & "Icon PNGs/" & characters 1 thru -6 in thisIcon & ".png" as string)
	do shell script "sips -s format png " & quoted form of ((theResourcesPath & thisIcon) as string) & " --out " & quoted form of thePNGPath
	do shell script "sips --resampleHeightWidthMax 512 " & quoted form of thePNGPath
end repeat

tell application "Finder" to make alias file to (POSIX file theMagickFolderPath) at desktop

set the clipboard to theMagickFolderPath
display dialog "Ready to paste!" buttons {"Beenden", "Ok"} default button 2
return theMagickFolderPath
7 Likes

Nice! Thank you for sharing this!
My databases are much more colourful now :slight_smile:

1 Like

@BLUEFROG please consider a database icns file a “feature” request :slight_smile:

@BLUEFROG please consider a database icns file a “feature” request

I’m not sure in what context the request for The icns is being made.

The script above colorizes groups etc. on demand.

I’d like to do that for databases too. I already colorized databases by first creating an icns file out of the small 32x32 sidebar-database.png file and then colorized it but the result was not what I’m looking for.

@valente made nice colorized database icons but could only use an icon that’s similar to the png that DEVONthink uses because DEVONthink doesn’t ship with an icns for the databases we see in the naviagtion sidebar.

If DEVONthink would be shipped with one or you could upload one then user could create custom icns from that.

The script dialog’s options in english

property menuRemove : “Remove thumbnail”
property menuColorPicker : “Show color picker”
property menuRevealFile : “Reveal files used in selection”
property menuRevealDefaultColors : “Reveal bookmarked colors”
property menuDeleteUnusedFiles : “Delete unused files”
property menuCreatePreviewRecords : “Create preview records”
property menuRevealNonMagick : “Set selection to records without Magick thumbnail”
property menuEnterMaintenance : “Show more options”