Help needed regarding mail auto download attachments script and flaky rules on macOS Mojave

Initially I wanted to have a mail rule triggering an apple script to save specific mail attachments to my desktop for further processing. While fiddling around I tried to debug wether the script was faulty or if mail rules where screwing up (or me, for a matter of fact). So I set up a simple rule to test:

If subject line equals “test” flag mail with green flag marker.

To test, I sent myself a mail from my account resulting in the mail not being flagged. If I alter the rule and confirm “apply to all existing mails” the exact same message receives the flag. If I now send the exact mail again it will work automatically when the mail finds its way into my inbox. If I try it a third time it will not be flagged.

Seemed strange, so I asked my girlfriend to send me two or three separate mails with the subject line “test” and it got flagged every time.

Between myself testing and asking my girlfriend I thought something was wrong with mail, so I went ahead and cleared all preferences while starting mail up, and even followed some articles asking to delete plist files and so on… This didn’t have any positive effects.

All this is happening on macOS Version 10.14.4 (18E226) and mail Version 12.4 (3445.104.8) with a personal gmail account connected. The external mail was also sent through mail on macOS and an attached gmail account.

Since mails from an external sender got processed I thought I’d give the download script another chance, which unfortunately did not work. I can’t credit anyone due to it being found on the interwebs but I’ll post it here, anyway. Maybe someone has an idea and could check if it works.

use AppleScript version "2.4"
use scripting additions

using terms from application "Mail"
     on perform mail action with messages messageList in mailboxes mbox for rule aRule
	--	Save on DesktopPath 	
	set desktopPath to (path to desktop) as string
	tell application "Mail"
		set selectedMessages to the selection
		repeat with aMessage in selectedMessages
			repeat with anAttachment in mail attachments of aMessage
				set attachmentName to name of anAttachment
				save anAttachment in file (desktopPath & attachmentName)
			end repeat
		end repeat
	end tell
    end perform mail action with messages
end using terms from

If you read this far: thanks for taking the time. I appreciate it and of course any hints and thoughts on why my self-sent mails are not being processed but external ones are, as well as why the script might not work.

Phew :wink: …that was longer than intended, but since this is my first post on MPU and I didn’t quite find similar issues I really wanted to give all information possible. If I did miss an obvious post/solution, please feel free to delete this issue and redirect me.

Best wishes to all of you,

PS: I have already found plenty of great information here as a silent reader and am happy to finally take a step into participation. This is a great forum! :+1:


I’ve investigated and tested some more. It seems that it is not enough to send a mail via gmail to ones own address just with an added dot… for differentiation. Mails from “real” external senders get processed fine.

…so I researched some more and found a script over at the keyboard maestro forum and tested it. Luckily I received an invoice during that test and it worked just fine. In case anyone is looking for the same functionality, I’ll link the respective post. The first script posted by “eurobubba” works great — see Save Mail attachments from specific people: