Hi Yvan, again many thanks for your kind offer however I will decline it because the error is unrelated to the actual attachment size, type or number of them.
For example, I can attach a single, modest or outrageous (300x) attachments of various size WITHIN the limited of the EMAIL sendmail attachment size quota, email it and then the processes the RECEIVED INBOX statement we’ve been dealing with in previous post will fail.
I can confirm in the last 10 minutes that I DO NOT GET THE ERROR on OS X 10.9.x or as far back as OS X 10.5. I CONFIRM that the set of applescripts that use these “mail attachment” terms, functions correctly on one of our OS X 10.9.x netboot (complete) test and diagnostic systems.
As I wished to be sure that I will have the “offending” messages in Mavericks, on my Yosemite volume, I moved them from INBOX of iCloud into a “standard” mailbox named “aaa”.
When I was in Mavericks, I imported these messages.
After the import process, under Mavericks, I selected all the messages available in my iCloud INBOX and ran the script : I didn’t got the error #-10000.
Then I selected the imported messages and ran the script : no more error #-10000.
Back under Yosemite, I selected the messages from the mailbox “aaa” and ran the script.
No more error #-10000.
I tried to move back the messages in the INBOX of iCloud account but no luck, some of them moved correctly, others remained in “aaa”.
As I am curious, I forwarded one of the message which gave the error #-10000 to my gmail address.
At this time I didn’t received it.
Yvan KOENIG (VALLAURIS, France) lundi 19 janvier 2015 14:54:30
I filed a bug report (below) with Apple: Nov. 2014 . Apple closed my Bug report on this as a duplicate
BUG REPORT:
As of 10.9 and 10.10 ( Yosemite) you can no longer access Mail.app’s ‘mail attachments’ from Applescript.
This means you cannot save or count them.
You will 9 times out of 10 get resulting error “error “Mail got an error: AppleEvent handler failed.” number -10000”
This appears to happen for 90% of the emails that are in an inbox, individual or consolidated ones.
This bug is reproducible when using a “get selection” Applescripts
This bug is reproducible when Performing a “Run Applescript” action in the Mail.app mail Rules
Hi Mario,thanks for your comments. I believe you have just been lucky or fortunate that this procedure changed “something” on out mac’s ~/ account that caused data examination form the “mail attachments” code path not to fail on OS X 10.10.1.
Certainly the removal of those Apple Mail indexes (a good old trick) causes a rebuild (which one may do indirectly to a less effective manner) through the Mailbox Application menu.
Our testing has manifested this error 99% of the time with a NEW mail account with a single message or the other extreme a 2001 email box with an inordinate number of messages and attachments.
Yvan made a point of this earlier.
Sadly this is looks still like a DEFECT in the implementation of the Applescript term “mail attachments” in OSx 10.10.1.
Form our experience so far, keep your fingers and legs crossed because this failing symptom will return when you least expect it… good Luck!
Hi Mark, yes I recall running over whilst searching this issue your post or similar somewhere that this issues had been logged with Apple. Thanks for doing this back in November. We have only seen this since December when we migrated all out production stuff from OS X 10.9.5 to 10.10.1.
AN adjuct to this albeit “noise” was that SOME OS X 10.7.x Apple Script mail terms caused -11000 and -10000 failures with “assertion” errors and “thread out of line” messages and Apple resolved this expeditiously at the time. Although, I am surprised that seeing a fair few of us have had this issue that it was not seen during Yosemite beta testing…
I agree with your own findings that this is a DEFECT in the processing of the term “mail attachments”. I’d like a workaround of course.
Alas we will have to wait and deal with our situation manually as we rely somewhat on APPLE Mail rules.
All, thanks again for your comments and ideas.
I will update this thread and close it once a satisfactory resolution is found.
Don’t know why but I was hoping that since apple have screwed some of the commands in JXA , like not being able to get the album art using rawdata of data for iTunes. Then maybe they had done the reverse here.
So tried it.
Mail = Application('Mail')
var theAtt =Mail.selection()[0].mailAttachments()[0].name()
theAtt
//--On My Mac mailbox: --> "photo 1.JPG"
//--iCload mailbox: --> Error -10000: AppleEvent handler failed.
And pretty much the same results. Same email but one stored in mailbox ‘On My Mac’ and one in the inbox (icloud)
Hi Mark, that’s also very interesting. Thanks for that post. This flaw in the “mail attachment” term processing will have to be addressed by an Apple OS X internal s/w fix and I have resigned to having to wait for it.
BTW for you and other readers the continued thread fro Apple forums user twtwtw has some reasonable views concerning this issue.
Hi Shane, yes fair point! yeah this has been logged apparently by a few people since November 2014, including one of the people in this thread. Two people have pointed out that it has been accepted or made a DUPLICATE or some terminology that means it has been acknowledged as a defect by Apple.
[whinge] I hope it’s resolved soon OS X 10.10.2 because the production workflows we use from clients has some reliance on this term “mail attachment” in our mail rules.
point 1 : I sent my own report
At this time it’s not flagged as a duplicate. Maybe because the given details made a difference.
point 2 : At this time the problem is always striking in the late 10.10.2 beta version.
Yvan KOENIG (VALLAURIS, France) vendredi 23 janvier 2015 11:10:07
Running the simplest script throws a -10000 error for any reference to “mail attachments.” Since the base access to attachments is broken, am I correct in assuming that any and all scripts to automatically save our incoming attachments to a “downloads” folder are impossible?
Simple to reproduce; Select a mail item with attachments and run the following simple script with Scriptp Debugger:
tell application “Mail”
set theMessages to selection
repeat with thisMessage in theMessages
set theAttachments to thisMessage’s mail attachments
end repeat
end tell
Yes sadly it is not fixed (still problematic) in OSX 10.10.4
It however is an inconsistent circumstance. I share the thought it is definitely “cache” related. The hit and miss is very difficult to set up a test and the information is still the “-10000” event regardless of the syntax used to pull the attachments(s) by message
The assertion error logging is also inconsistent.
I’m looking for a workaround because this error has been an obstruction to some production workflow since we migrated to OS X 10.10 last year
Just to add $.02. I’m having the same problem with this code snippet, which (for now) simply wants to count the number of attachments in the current selection. If each time I just select one message with a single attachment, for some messages the script works, but others throw the dreaded -10000 error. In the code below, with some messages the display dialog with “attachmented” never happens.
set selectedSize to 0 as integer
set attachmentCount to 0 as integer
tell application "Mail"
try
set selectedMessages to selection
end try
end tell
set selectedCount to count of selectedMessages
display dialog "here 1" -- DEBUG
with timeout of (30 * 60) seconds
repeat with theMessage in selectedMessages
tell application "Mail"
try
display dialog "here 1a" -- DEBUG
set selectedSize to selectedSize + (message size of theMessage)
display dialog "selectedSize: " & selectedSize -- DEBUG
set theAttachments to the mail attachments of theMessage
display dialog "attachmented " -- DEBUG
on error errStr number errorNumber
display dialog "Error in theAttachments:" & return & ¬
"errStr: " & errStr & return & ¬
"number: " & number & return & ¬
"errorNumber: " & errorNumber
error errStr number errorNumber
end try
end tell
set attachmentCount to count of theAttachments
end repeat
end timeout
Model: iMac
AppleScript: (Xcode) 2.4
Browser: Chrome 44.0.2403.155
Operating System: Mac OS X (10.10)
Hi Swampman, yes these similar snippets of applescript always yield the same result - the “-10000” apple event issue.
FWIW, it is NOT consistent despite my comment above. Interestingly its point more to a “cache” related scenario. Right now we DONT see this issue. It will occur again soon though.
I’ve upgraded to  OSx 10.10.5 on clients and also the servers and it still happens.
It rather seems to be related to some TIMING or access.
As you point out merely attempting to derive a COUNT of attachments manifests this error.
I am trying to determine what the “assertion” issue is when it happens. No info sadly at this stage.
And… for the story here, this happens ALSO email accounts that are hosted on my own OSx server using OSX server mail server. so it’s unrelated specifically to iCLOUD or any other email server/service. It just seems to manifest itself on OSX in both automator environment and Applescript.
As I am curious, I will import the message in El Capitan to check if it errors also in it.
Mauybe useful for you:
The Console reported the oddity with :
20/08/2015 15:28:56,521 Mail[259]: *** Assertion failure in -[MCMimeBody dataForMimePart:], /SourceCache/Mail/Mail-2104/MailCore/MIME/MCMimeBody.m:362
20/08/2015 15:28:56,522 Mail[259]: An exception was thrown during execution of an NSScriptCommand…
20/08/2015 15:28:56,522 Mail[259]: This method must be called off the main thread
Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) jeudi 20 août 2015 15:27:06