Mail Rule - Add attachments / nur PDF importieren in bestimmte Gruppe

Hallo, ich würde gerne das folgendes das Script

Mail Rule - Add attachments to DEVONthink.scpt

so anpassen, dass diese nur PDF Dokumente importiert. Am besten so, dass die Dateien direkt in eine bestehende Gruppe importiert werden.

Ich denke es sind wohl dieser Eintrag in den folgenden Zeilen.
Wobei wohl “mail attachments” auf die Dokumentenart PDF eingrenzen muss, aber halt wie?

				repeat with theAttachment in mail attachments of theMessage

tell application id "DNtp"
      set theDatabase to open database "/Users/Name/Documents/DEVONthinkDB/DBName.dtBase2"
      set theDatabase to database "DBName"
               set theGroup to get record at "/MeinNeueGruppe" in theDatabase
               set theAttachmentRecord to import theFile to theGroup
               set URL of theAttachmentRecord to theSender
		       perform smart rule trigger import event record theAttachmentRecord
end tell


Freue mich über jede Info.

System: Apple Mail, BigSur, Devonthink3

Die einfachste Möglichkeit ist wahrscheinlich, die Endung des Pfades zu überprüfen:

if theFile ends with ".pdf" then
-- Import file
end if
1 Like

@cgrunenberg das funktioniert, super :slight_smile:

Info für alle die das einmal brauche, wenn man in der AppleMail Regel die Mail in einen anderen Ordner verschiebt und dann ein Script anwendet, dann geht das nicht mehr. Da der temporäre Pfad nicht mehr stimmt. Mann muss dann also mit einer 2. AppleMail Regel die Mail verschieben, nachdem das Script abgearbeitet wurde.

Eleganter wäre es natürlich anstelle der Endung .PDF den Dokumententyp für PDF/PS zu haben. Dann würden auch PDF Dokumente ohne Endung entsprechend verarbeitet.

using terms from application "Mail"
	on perform mail action with messages theMessages for rule theRule
		tell application "Mail"
			set theFolder to (POSIX path of (path to temporary items))
			repeat with theMessage in theMessages
				set theSender to the sender of theMessage
				repeat with theAttachment in mail attachments of theMessage
					try
						if downloaded of theAttachment then
							set theFile to theFolder & (name of theAttachment)
							tell theAttachment to save in theFile
							tell application id "DNtp"
								set theDatabase to open database "/Users/UserName/Documents/DEVONthinkDB/DBName.dtBase2"
								set theDatabase to database "DBName"
								set theGroup to get record at "/GrouppenName" in theDatabase
								
								if theFile ends with ".pdf" then
									-- Import file
									set theAttachmentRecord to import theFile to theGroup
									-- set theAttachmentRecord to import theFile to incoming group
								end if
								
								set URL of theAttachmentRecord to theSender
								perform smart rule trigger import event record theAttachmentRecord
							end tell
						end if
					end try
				end repeat
			end repeat
		end tell
	end perform mail action with messages
end using terms from```