Mail script only working manually

I use the Mailscript “Add attachement to Devonthink” to automatically send pdfs in incoming mails to Devonthink. It works perfectly fine if I do it manually after new mails came in, but it is not working automatically. For testing I put additional actions in the rule and these work automaticially. Only the transfer of the pdf won´t work.

Any ideas to solve this problem? Or an idea for a different workflow? Thank you very much!

The one for Mail rules or the one in the Scripts menu extra? Did you enable full disk access for DEVONthink 3?

The one for the mail rules, full disk access and automation enabled.

can you please post your rule here?


– Import attachments of selected messages to DEVONthink.

– Created by Christian Grunenberg on Fri May 18 2012.

– Copyright (c) 2012-2020. All rights reserved.

tell application “Mail”


tell application id “DNtp”

if not (exists current database) then error “No database is in use.”

set theGroup to preferred import destination

end tell

set theSelection to the selection

set theFolder to (POSIX path of (path to temporary items))

if the length of theSelection is less than 1 then error “One or more messages must be selected.”

repeat with theMessage in theSelection

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 theGroup

set URL of theAttachmentRecord to theSender

perform smart rule trigger import event record theAttachmentRecord

end tell

end if

end try

end repeat

end repeat

on error error_message number error_number

if error_number is not -128 then display alert “Mail” message error_message as warning

end try

end tell

put ``` at top and bottom of the above script to make it easiest to review.

the script is fine. - what do you enter for the AppleMail rule?

Bildschirmfoto 2024-01-24 um 16.38.51

It runs perfectly when I apply the rule manually, but not automatically.

Makes me wonder whether the rule is actually performed as it doesn’t make a difference for the script or DEVONthink how it’s done.

Why do you have this set to process every email ?
You should strive to be as specific as possible when automating things like this.

PS: Apple Mail handles the rules and if they trigger. We don’t. If the rule doesn’t trigger, for whatever reason, the actions don’t happen. That includes running an AppleScript.

Yes, same here, I have no explanation for that. I will test the same setup tomorrow on a different mac.

It is just for demonstration, I also tried it with “attachement type is pdf” as trigger. The rule in general is triggered, I tried it with a second action (just add a color) and this part is automatically done, but the script part not.
Bildschirmfoto 2024-01-24 um 17.11.53

try using Erfüllt alle (any) then it will work.

What OS?

Sonoma 14.2 on MacMini M1

Tried it today on a MacBook Pro with Sonoma 12.6.8 and it works perfectly. Does Devonthink need any addtl. rights other than “full disk access”?

Full disk access and automation of Mail should be sufficient. But scripting on Sonoma is not that reliable as it used to be in my experience, does rebooting fix this?

I erased all preferences and accounts in Apple mail, set it up from scratch and erased / reinstalled the scripts. After rebooting it works very well now.
Thank you for all tips!