Sandro Sandro - 29 days ago 7
AppleScript Question

Can't access to mail attachments in mail app via apple script

Let's assume that in the following code

tell application "Mail"
tell first account
tell first mailbox
set myMessage to first message
set myAttachment to mail attachments of myMessage
end tell
end tell
end tell


the first message of the first mailbox of the first account actually has attachments. Let's further assume that the account in question is a GMail account (maybe that proves relevant) and that I am trying this on El Capitan.

On the "set myAttachments" line I always get the error "error in apple event routine, -10000" (losely translated from German). I have read in old threads that there was indeed a bug in the access to attachments. But I also saw a new thread that was talking specifics about how to best handle them (no mentioning of having no access at all).

What am I missing? Does it work? Maybe in general but not with GMail? Do I have to do something specific?

Thanks!

Sandro

Answer

The exact syntax is "mail attachement of myMessage" (without "s"). The script bellow is working perfectly on my side for selected emails :

tell application "Mail"
activate
set ListMessage to selection
repeat with aMessage in ListMessage
    set AList to every mail attachment of aMessage
    repeat with aFile in AList
        if (downloaded of aFile) then
            -- do something with aFile 
        end if
    end repeat -- next file
end repeat -- next message

end tell

Are you sure the the message with attachement is in your first account/first mailbox ?