Hi! I’ve got an odd thing happening with a Mail Rule I have set up, with an AppleScript action to import the email into DEVONthink. The AppleScript seems to run correctly, but it only runs when new email arrives, but it acts on only the old email that was already in the inbox, and not on the new email.
So for instance, if I send email1 that meets the rule criteria, Mail does nothing. But then I send email2 that also meets the criteria, the rule successfully runs the AppleScript on email1, but email2 stays in the Inbox, untouched. I’m trying to figure out why it triggers only on old email, and how to fix this, so that the new mail is also processed by the rule?
My Mail rule looks like this:
And my script looks like this:
-- Mail Rule - Add messages to DEVONthink
-- Created by Christian Grunenberg on Mon Apr 19 2004.
-- Copyright (c) 2004-2020. All rights reserved.
-- Modified by Mark Boszko, 2025-05-06
-- this string is used when the message subject is empty
property pNoSubjectString : "(no subject)"
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with theMessage in theMessages
try
tell theMessage
set {theDateReceived, theDateSent, theSender, theSubject, theSource, theReadFlag} to {the date received, the date sent, the sender, subject, the source, the read status}
end tell
if theSubject is equal to "" then set theSubject to pNoSubjectString
tell application id "DNtp"
set theRecord to create record with {name:theSubject & ".eml", type:unknown, creation date:theDateSent, modification date:theDateReceived, URL:theSender, source:(theSource as string), unread:(not theReadFlag)} in incoming group of database "Database Name"
perform smart rule trigger import event record theRecord
end tell
end try
set read status of theMessage to true
set theAccount to account of mailbox of theMessage
set mailbox of theMessage to mailbox "Trash" of theAccount
end repeat
end tell
end perform mail action with messages
end using terms from
Again, the script seems to work fine, when it does run, but it’s not triggering on the new mail that arrives. The email just sits in the inbox until another new mail arrives, and then only the old email gets processed. Perplexing.
I have tried setting the trigger to be “To” a specific email, instead of using the email account, but that gave the same result. Is there a different trigger I should use?
I realize this is probably a Mail trigger issue, and not much to do with the script, but hoping that someone here might have an idea. Thanks!