Thanks @Blanc I went through the routine. But now there are no documents imported to DT.
So I’m executing my Mail Script but there are no documents in my inbox of DT.
Before this routine a few AppleScripts worked as expected (as you can see at my screenshots posted earlier).
Ok, so I’ve just sat down at home to try this - and I can confirm it does not work. It will work once the attachment has been opened from Mail once.
@cgrunenberg the script in question sets theFolder to a folder which in my tests is initially empty; I can see the attachment inline in the Mail, but only once it has been manually opened is it placed in the temporary folder (and only then does the script work). Is there any way to adapt the script to trigger Mail to get/download the attachment to theFolder without having to manually open the attachment?
Certainly not automatically, no; I’ll sit down later this evening and see if I can find anything in Mail’s AppleScript directory which would cause Mail to put the attachment in the temporary folder without manually opening it (@pete31 I wonder if you have any ideas off hand?)
-- Mail Rule - Add attachments to DEVONthink
-- Created by Christian Grunenberg on Fri May 18 2012.
-- Copyright (c) 2012-2020. All rights reserved.
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
-- if downloaded of theAttachment then
set theFile to theFolder & (name of theAttachment)
tell theAttachment to save in theFile
tell application id "DNtp"
set theAttachmentRecord to import theFile to incoming group
set URL of theAttachmentRecord to theSender
perform smart rule trigger import event record theAttachmentRecord
-- end if
end perform mail action with messages
end using terms from
What I have done is to comment out the downloaded condition. It would seem Mail is reporting the attachment has not been downloaded, so that Christian’s script breaks off at that point. However, for me anyway, the attachment is available to be saved - after commenting out the condition the script/rule works as expected. If the attachment really isn’t available I would assume that would have no further negative impact, as the save command is in a try-loop anyway.
In case you are not aware: you can access the script by selecting “Im Finder öffnen” in the last of your images in your original post. That will open the folder containing the scripts; open the script in question, add -- in the two locations (that is before if and end if) and save.
I tried the comment-out proposal by @Blanc but it doesn’t work for me unfortunately I tried it many times, restarted each of the programs.
I’m running 10.15.7 on an intel mac, devonthink 3.6.3
I wonder why there’s a set of scripts named almost the same in Library/Scripts/Applications/Mail which works (but only manually when selecting emails) and starts with tell application "Mail" (not using terms...). I did the same change as to the Script in “Application Scripts/com.apple.mail”