Archive group: Script to create new database with selected group and archive new database

Here’s how it can be done in AppleScriptObjC

-- Get plain text from RTF(D) Custom Meta Data

use AppleScript version "2.4"
use framework "Foundation"
use scripting additions

property theCMD_Identifier : "testrtf" -- set your Custom Meta Data identifier

tell application id "DNtp"
	try
		set theRecords to selected records
		if theRecords = {} then error "Please select some records."
		
		repeat with thisRecord in theRecords
			set thisRecord_CMD_RTF to get custom meta data for theCMD_Identifier from thisRecord
			
			if thisRecord_CMD_RTF ≠ missing value then
				set thisRecord_CMD_RTF_plainText to my getPlainTextFromRTFDdata(thisRecord_CMD_RTF)
			else
				set thisRecord_CMD_RTF_plainText to ""
			end if
			
			-- do something with variable "thisRecord_CMD_RTF_plainText"
			
		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
		return
	end try
end tell


on getPlainTextFromRTFDdata(theData)
	try
		set theNSData to (current application's NSArray's arrayWithObject:theData)'s firstObject()'s |data|()
		set {theAttributedString, theError} to (current application's NSAttributedString's alloc()'s initWithData:theNSData options:(missing value) documentAttributes:(missing value) |error|:(reference))
		if theError ≠ missing value then error (theError's localizedDescription() as string)
		set theString to theAttributedString's |string|()
		return theString as string
	on error error_message number error_number
		activate
		if the error_number is not -128 then display alert "Error: Handler \"getPlainTextFromRTFDdata\"" message error_message as warning
		error number -128
	end try
end getPlainTextFromRTFDdata
1 Like