Devonthink 4 - PDF extraction not working

Hi

since migrating from DT3 to DT4 Beta 3 my AppleScript to extract the pdf from the email in a smart rule has stopped working and complains: on performsmartrule (The variable theRTF is not defined)

unsure why this is now an issue.

Fullcode:

on performSmartRule(theRecords)
	tell application id "DNtp"
		set tmpFolder to path to temporary items
		set tmpPath to POSIX path of tmpFolder
		
		with timeout of 14400 seconds
			repeat with theRecord in theRecords
				if type of theRecord is unknown and path of theRecord ends with ".eml" then
					set theRTF to convert record theRecord to rich
					set theURL to reference URL of theRecord
					set newGroup to false
					
					try
						if type of theRTF is RTFD then
							set thePath to path of theRTF
							set theGroup to parent 1 of theRecord
							set theName to name of theRecord
							set theModificationDate to the modification date of theRecord
							set theCreationDate to the creation date of theRecord
							set theAdditionDate to the addition date of theRecord
							
							tell rich text of theRTF
								if exists attachment in attribute runs then
									
									tell application "Finder"
										set filelist to every file in ((POSIX file thePath) as alias)
										repeat with theFile in filelist
											set theAttachment to POSIX path of (theFile as string)
											
											if theAttachment does not end with ".rtf" and theAttachment does not end with ".png" then
												try
													with timeout of 7200 seconds
														
														-- Importing skips files inside the database package,
														-- therefore let's move them to a temporary folder first
														
														set theAttachment to move ((POSIX file theAttachment) as alias) to tmpFolder with replacing
														set theAttachment to POSIX path of (theAttachment as string)
														tell application id "DNtp"
															if newGroup is false then
																set newGroup to create record with {name:theName, type:group, modification date:theModificationDate, creation date:theCreationDate, addition date:theAdditionDate} in theGroup
															end if
															set importedFile to import path theAttachment to newGroup
															set URL of importedFile to theURL
															set the modification date of importedFile to theModificationDate
															set the creation date of importedFile to theCreationDate
															set the addition date of importFile to theAdditionDate
															
														end tell
													end timeout
												end try
											end if
										end repeat
										
									end tell
									if newGroup is not false then
										tell application id "DNtp"
											move record theRecord to newGroup
										end tell
									end if
								end if
							end tell
						end if
					on error msg
						display dialog msg
					end try
				end if
				
				delete record theRTF
			end repeat
		end timeout
	end tell
end performSmartRule

Appreciate any help

Firstly, did you read this…

Secondly, DEVONthink 4 can import attachments on its own when importing emails. See the Files > Emails > Automatically import attachments to always import available attachments when you import emails. Or use Tools > Import Email Attachments for selected, already imported emails.

Lastly, the Apple Mail script Add attachments to DEVONthink works for DEVONthink 4.

The type of emails is now email as requested.

Okay i can use import attachment in a smart rule, but my script used the email subject as the name for the PDF how do i do this in a smartrule?

By using the Change Name action and the Properties > Subject placeholder…

This is discussed in the Windows > Predicate Editor section of the Help.

Hi

Doesnt work if type of theRecord is email and path of theRecord ends with ".eml" then
Becasue email is deleted and no PDF is produced.

I need to have the script working becasue im only moving groups on completion of the script. i cant find any other way to know if the pdf has been complete because i cant find a way to automate a process of searching within a group to find out if the pdf is present.

This is unnecessary.

1 Like

Thanks, removed. But the problem seems to be that the .rtfd files are going into the Mac’s trash bin.