Save mail text and attachments

hmmm this is very similiar and could be useful for what i was wanting to do a few weeks ago. printing a mail message that meets a rule. but i tried adding the do shell lpr command to this and its not working. any ideas?

More AppleScript frustration

You can choose “Print” from the Mail application, and it prints like any other app.

Try to say


tell application "Mail"
	set x to selection
	set x to first item of x
	print x
end tell

==> Error.

Also


tell application "Mail"
	set x to selection
	set x to first item of x
	tell app "Finder" to print x
end tell

==> Error.

You could always use the “content saving” portion of my previous script and then tell the Finder to print that file, I guess.

Or try telling Mail to Save the message and then having the Finder print that file.

I should never have re-read Chapter 19 of Matt Neuburg’s book - that always puts me in a frustrated mood. APPLE - WHY DON’T YOU TELL US WHAT COMMANDS EACH OBJECT RESPONDS TO, FOR THE LOVE OF ALL THAT IS HOLY.

Hi johny, me again

I have a problem with making the formprocessor send the email in plantext. I have to set entryption type of the form to enctype=“multipart/form-data” or it errors because it cant send the attachment in plaintext “mode”.

Damn its so anoying. I don’t think I am going to be able to do it.

Well using all the info here (many thanks) I encounter some (little) problems.
First the info:
I am using apple.mail rules as follows:

Rule 1: When mail arrives with subject is: PC_FROM_KID run next applescript ~/Library/ScriptingAdditions/SaveAttachmentsMail.scpt
Rule 2: When mail arrives with subject is: PC_FROM_KID Move mail to emailbox Activity Logging

The above script looks like this:
using terms from application “Mail”
on perform mail action with messages theMessages
tell application “Finder” to set pathToAttachments to “iMacHD:Users:CarFra:Library:Logs:ActivityLogging:Kid:”
tell application “Mail”
repeat with theMessage in theMessages
set theText to content of theMessage
if theMessage’s mail attachments is not {} then
repeat with theAttachment in theMessage’s mail attachments
set theFileName to pathToAttachments & (theMessage’s id as string) & space & theAttachment’s name
try
save theAttachment in theFileName
on error errnum
end try
end repeat
end if
set theFile to ptd & "Message Number " & (theMessage’s id as string)
set theFileID to open for access file theFile with write permission
write theText to theFileID
close access theFileID
end repeat
end tell
end perform mail action with messages
end using terms from

tell application “Mail”
set myMessages to selection
tell me to perform mail action with messages myMessages
end tell

Well so far so good.
The (rare) problem I encounter is as follows:

After receiving the mail the mail has been moved according rule 2 to the mentioned mailbox.
But no mail attachment has been saved.

Wrong script?
Well if I move manually the mail back to the inbox, click on the mail and click on apply rules everything goes well.

Rule 1 saved my email in the mentioned folder
Rule 2 moved my email to the mentioned emailbox

So at that point everything went as I had in mind.

But after receiving the next mail only rules 2 (moving email) has been applied.

Some ideas here?

thanks Frank

I see this is an old thread but I am trying to pull the content of a message which I can do manually through a script but the mail rule will not activate the script. it performs the rest of the rule task such as move and change color but not the applescript. I have been scouring the list and web for solutions to why mail won’t execute the script but have not found any answer