Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

AS called from mail .app rule - *** Assertion failure in -[MimeBody dat

Guys, some help if you would. I have an applescript called from a mail rule .. Very simple. Just gets filters attachments of a kind , puts them into a folder.

For some reason (beats me) I noticed I'm getting:

+Mail[992] * Assertion failure in -[MimeBody dataForMimePart:], /SourceCache/Message/Message-1082/Message.subproj/MIME.subproj/MimeBody.m:422+
+This method must be called off the main thread+

in the /var/logs (console.app)

• mail grinds a bit while it logs this messge with many lines of diagnostics..

however the script works fine and the results are obtained.

I've looked around for this and not found an explanation.

any clues?

thanks

MACPRO Nehalem 8CORE 2.93GHz 12GB, w/12TB + 1xUnibody MBPro 2.8Ghz FCS 3, CS4, Mac OS X (10.6.5), Panasonic HVX200+2x16GB P2+ATTOR380+PROAVIO Raid0+H380+2 x HP LTO4 tape drives

Posted on Jan 5, 2011 12:57 AM

Reply
3 replies

Jan 5, 2011 3:47 AM in response to Warwick Teale

found and implemented the following:

*1) Issue causing the symptom:*
Looks like's there's a circumstance after OSX 10.5 when running an applescript from a mail.app rule. This issue is where one calls the apple script and within the applescript performs some processing using the mail.app ( Tell application "mail") or performing direct references/methods to it whilst inline. The error message notes this as +the method must be called of {out of??} the main thread+.
After some long time looking I found these links , the first one from Horito was most helpful and obvious. (thanks mate).

http://discussions.apple.com/message.jspa?messageID=12068548
and this eon to which he refers.... http://hints.macworld.com/article.php?story=20080314184621760

Simply all that is needed it ro make the mail.app specific methods into another method outside the main call ofthe applescript called by the mail rule.

*2) Here's what i did:*

Took the main bits and pieces of the apple script main and made a handler with all the mail.app stuff in it

global some global_for_later1
global another global_for_later2


using terms from application "Mail" -- directly called from MAIL.app rule
on perform mail action with messages bunch of_msgs_from_mailrule

(* any other set up initialisation stuff here *)

(* call main handler outside of main thread to avoid error " * Assertion failure in -[MimeBody dataForMimePart:], /SourceCache/Message/Message-1082/Message.subproj/MIME.subproj/MimeBody.m:422 This method must be called off the main thread " *)

my main mail_script_handler(bunch_of_msgs_from_mailrule)

end perform mail action with messages
end using terms from




(* _ avoid assertion failure error messages for mail rule applescripts _*)
(* _ move all the work from the main thread _*)

using terms from application "Mail" -- using mail app defs
on main mail_script_handler(bunch_of_msgs_from_mailrule)

(* put goodies here .. *)
(* get mail attachments and sav them etc *)
(* use other services / handlers ... tell application "database Events" etc etc *)

return 0
end main mail_scripthandler -- end of the main thing
end using terms from




Workround? : yes works ok and not any effort to do really. Ths circumvention stops the messages coming out in the /var/console such as :

+05/01/2011 6:04:58 PM Mail[4121] * Assertion failure in -[MimeBody dataForMimePart:], /SourceCache/Message/Message-1082/Message.subproj/MIME.subproj/MimeBody.m:422+
+This method must be called off the main thread+
(
+ 0 Message 0x00007fff866f06e4 -[MFAssertionHandler _handleFailureWithPreamble:description:arguments:] + 137+
+ 1 Message 0x00007fff866f0649 -[MFAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 220+

so I guess the circumstance doesn't hap[en.

I will leave this open for a while in case anyone has some other fixes.

Thansk to Hiroto in http://discussions.apple.com/message.jspa?messageID=12068548 for his great post on this issue.

HTH
Happy New Year from Hong Kong!.

Jan 5, 2011 9:34 AM in response to Warwick Teale

Hello Warwick Teale,

Very interesting to know that it suffices to invoke a custom handler in the script run by mail rule in order to avoid the said error. No need to dance with osascript.

Also I think I have misunderstood the error message so that some method must be called FROM the main thread. But indeed, as I understand now, they must be called OUT OF (= NOT FROM) the main thread.

Perhaps custom handler call in AppleScript run by mail rule detaches a sub thread, which satisfies the assertion stated in the error.

Anyway glad to know my old post has helped somehow.
And thank you for the new solution, which I believe is the simplest.

A Happy New Year from Japan !
Hiroto

Jan 5, 2011 7:17 PM in response to Hiroto

HI Hiroto! many thanks for your heads up. Yes this seems to be quite solid now. I did go down the OSASCRIPT path and had some kind of results but pass parms to and from became awkward and nearly having to resort to flat files as a transfer medium between .SH and .SCPT's.

In my haste to post last night I did omit one important thing in the example code.

This is that one must add addressability/association to the MAIL.app when explicitly utilising any mail.app functions etc within the second out of line handler. (In this example it is the code associated with called mainmail_scripthandler .


tell application "Mail"
-- do all mail.app related stuff inside or with TELL application "MAIL" to do_something
-- else one will experience some "Assertion failed errors"
end tell -- using mail.app


If this is *not done* one will still experience the *Assertion failure errors* as before.


using terms from application "Mail" -- directly called from MAIL.app rule
on perform mail action with messages bunchof_msgs_from_mailrule
(* any other set up initialisation stuff here *)
my mainmail_script_handler(bunch_of_msgs_from_mailrule) -- call out of line below
end perform mail action with messages
end using terms from
(* avoid assertion failure error messages for mail rule applescripts *)
(* move all the work from the main thread to here *)
using terms from application "Mail" -- using mail app defs
on mainmail_script_handler(bunch_of_msgs_from_mailrule)
(* put goodies here .. *)
tell application "Mail"
-- do all mail.app related stuff inside or with MAIL.app
-- else one will experience some "Assertion failed errors"
end tell -- using mail.app
return 0
end mainmail_scripthandler -- end of the main thing
end using terms from


Thanks for the further explanation Hiroto. At this stage I shall press on with this work round which seems quite robust and simple.

w
HK - looking forward to Chinese New Year soon!

AS called from mail .app rule - *** Assertion failure in -[MimeBody dat

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.