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

Print Mail Script

Has anyone created a print mail script that can be used in the rules to automatically print an html email mesage that they are willing to share?

Or point me in the right direction.

Thank you.

G5 Server Mac OS X (10.3.9)

Posted on Feb 13, 2006 10:46 AM

Reply
Question marked as Best reply

Posted on Feb 13, 2006 10:14 PM

The following should work (both as a rule action and when run from the script editor - it will then print all selected messages). I don't consider it to be pretty but since there is no real "print" action available, it will have to do for now...

Please also give Apple feedback that they should add a proper "print" command to both, the rule actions and AppleScript:
http://www.apple.com/macosx/feedback/

<pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; padding: 0.2em; font-size: 10px; width:500px">on run
tell application "Mail" to set selectedMessages to get selection
using terms from application "Mail"
perform mail action with messages selectedMessages
end using terms from
end run

using terms from application "Mail"
on perform mail action with messages selectedMessages
tell application "Mail"
repeat with eachMsg in selectedMessages
set theSource to source of eachMsg as text
set AppleScript's text item delimiters to "<HTML>"
try
set theSource to text items 2 thru -1 of theSource as text
on error
set AppleScript's text item delimiters to "<html>"
try
set theSource to text items 2 thru -1 of theSource as text
on error
exit repeat
end try
end try
set AppleScript's text item delimiters to "</HTML>"
set theSource to text item 1 of theSource as text
set AppleScript's text item delimiters to "</html>"
set theSource to text item 1 of theSource as text
tell application "Finder" to set theFileName to ((path to desktop folder as text) & "Mail_tmp.html")
set theFile to open for access theFileName with write permission
set eof of theFile to 0
write "<html>" & return & theSource & "</html>" to theFile starting at eof
close access theFileName as file specification
tell application "Finder"
get properties of alias theFileName
-- make sure that the file will be opened by a browser…
set file type of alias theFileName to "HTML"
set creator type of alias theFileName to " "
print alias theFileName
delete alias theFileName
end tell
end repeat
end tell
end perform mail action with messages
end using terms from</pre>

Andreas User uploaded file

PB G4 Al 1.5GHz/1.25GB, PB G4 Ti 550MHz/768MB, iPod 10GB (2. Gen), AEBS & AEX Mac OS X (10.4.4) http://homepage.mac.com/aamann/
5 replies
Question marked as Best reply

Feb 13, 2006 10:14 PM in response to Rtg

The following should work (both as a rule action and when run from the script editor - it will then print all selected messages). I don't consider it to be pretty but since there is no real "print" action available, it will have to do for now...

Please also give Apple feedback that they should add a proper "print" command to both, the rule actions and AppleScript:
http://www.apple.com/macosx/feedback/

<pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; padding: 0.2em; font-size: 10px; width:500px">on run
tell application "Mail" to set selectedMessages to get selection
using terms from application "Mail"
perform mail action with messages selectedMessages
end using terms from
end run

using terms from application "Mail"
on perform mail action with messages selectedMessages
tell application "Mail"
repeat with eachMsg in selectedMessages
set theSource to source of eachMsg as text
set AppleScript's text item delimiters to "<HTML>"
try
set theSource to text items 2 thru -1 of theSource as text
on error
set AppleScript's text item delimiters to "<html>"
try
set theSource to text items 2 thru -1 of theSource as text
on error
exit repeat
end try
end try
set AppleScript's text item delimiters to "</HTML>"
set theSource to text item 1 of theSource as text
set AppleScript's text item delimiters to "</html>"
set theSource to text item 1 of theSource as text
tell application "Finder" to set theFileName to ((path to desktop folder as text) & "Mail_tmp.html")
set theFile to open for access theFileName with write permission
set eof of theFile to 0
write "<html>" & return & theSource & "</html>" to theFile starting at eof
close access theFileName as file specification
tell application "Finder"
get properties of alias theFileName
-- make sure that the file will be opened by a browser…
set file type of alias theFileName to "HTML"
set creator type of alias theFileName to " "
print alias theFileName
delete alias theFileName
end tell
end repeat
end tell
end perform mail action with messages
end using terms from</pre>

Andreas User uploaded file

PB G4 Al 1.5GHz/1.25GB, PB G4 Ti 550MHz/768MB, iPod 10GB (2. Gen), AEBS & AEX Mac OS X (10.4.4) http://homepage.mac.com/aamann/

Feb 16, 2006 10:02 AM in response to Andreas Amann

Many, many thanks.
Unfortunately, I could not get it to work.

In trying to diagnose the problem; I put a open message statement to ensure that it had made it to that point.

on run
tell application "Mail" to set selectedMessages to get selection
using terms from application "Mail"
perform mail action with messages selectedMessages
end using terms from
end run
using terms from application "Mail"
on perform mail action with messages selectedMessages
tell application "Mail"
repeat with eachMsg in selectedMessages
open eachMsg
set theSource to source of eachMsg as text
set AppleScript's text item delimiters to "<HTML>"


The message did not open.
Finding a sample rules script, I used the beginning of it, and could get to the open message statement okay.

using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with eachMessage in theMessages
open eachMessage
set theSource to source of eachMessages as text
set AppleScript's text item delimiters to "<HTML>"


But at last, the remainder of the script prduced no result.

I tried taking the script, both as is and as modified above, and commenting out the delete file statement, hoping to find a file left on the desktop. But no file left behind.

While not a working solution yet, it does help point the way.
Many thanks.

I did take the time to post a feedback on the link you supplied.

Rtg

Feb 22, 2006 5:13 AM in response to Rtg

Another person here cam up with the following. Does an open and close, but gets the job done, ie it prints:

using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
repeat with eachMessage in theMessages
my printme(eachMessage)
end repeat
end perform mail action with messages
end using terms from
on printme(x)
tell application "Mail"
activate
open x
tell application "System Events"
tell application process "Mail"
try
keystroke "p" using {command down}
keystroke return
keystroke "w" using {command down}
end try
end tell
end tell
close window x
end tell
end printme

Print Mail Script

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