Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Applications > Auto print Mail.app PDF attachments? Need your help

Auto print Mail.app PDF attachments? Need your help
Thread Tools
Cadaver
Addicted to MacNN
Join Date: Jan 2003
Location: ~/
Status: Offline
Reply With Quote
Jan 3, 2007, 07:50 PM
 
Here's the challenge - I periodically receive PDF files from a single specific email address. I'm trying to figure out a way to have Apple's Mail application automatically print the attachments when the email arrives.

Now, I'm not bad at Automator programming, but AppleScript is a bit beyond my level (last time I had to program anything similar, it was in AppleSoft FP BASIC!). I can write a script to tell an Automator "application" to run (one whole line - tell application "my_automator_action" to run) at least.

I've gone through all the built-in Automator actions combined with some others I've found online, but I've never been able to find a way to do it.

Any AppleScript geniuses have any thoughts??
     
itai195
Addicted to MacNN
Join Date: May 2001
Location: Cupertino, CA
Status: Offline
Reply With Quote
Jan 5, 2007, 04:39 AM
 
Okay, I'm not an AppleScript expert, so I couldn't get printing from my Mail rule to work and had to use both a script and an Automator workflow, but here goes.

This solution requires you to have a folder named Mail Attachments on your desktop. You can change this by editing the first line of the AppleScript. First, create your rule in Mail and use this script as its action:

Code:
property destinationFolder : (path to desktop as Unicode text) & "Mail Attachments:" using terms from application "Mail" on perform mail action with messages theMessages for rule theRule tell application "Mail" repeat with eachMessage in theMessages repeat with thisAttachment in eachMessage's mail attachments if (MIME type of thisAttachment) is equal to "application/pdf" then set thisFile to destinationFolder & name of thisAttachment save thisAttachment in thisFile end if end repeat end repeat end tell end perform mail action with messages end using terms from
Next, create an Automator workflow with these actions: Print Finder Items and then Move to Trash. Go to File > Save as Plug-in and save it as a Folder Action on the Mail Attachments folder, making sure to enable folder actions.

Now your rule should execute when messages are received from the address you specify, any PDFs received in messages caught by the rule will be saved into the Mail Attachments folder, the folder action will be triggered and the PDFs will get printed and then deleted.
     
kenneth1990
Fresh-Faced Recruit
Join Date: Jan 2007
Status: Offline
Reply With Quote
Jan 15, 2007, 05:08 PM
 
okay.... this is cool

but what if i want it to print any attachment? rahter than just a pdf file?

and am i able to just copy & paste or do i need to edit anything?

thanks in advance
     
itai195
Addicted to MacNN
Join Date: May 2001
Location: Cupertino, CA
Status: Offline
Reply With Quote
Jan 16, 2007, 04:18 AM
 
You can remove these lines entirely:

Code:
if (MIME type of thisAttachment) is equal to "application/pdf" then .... end if
That'll print all attachments. Or you can replace "application/pdf" with another MIME type if you want to print only a different type of file. Or you can change it to check against a list of types by doing this:

Code:
if (MIME type of thisAttachment) is in {"application/pdf", ... } then
Replacing the ellipses with a list of more MIME types you want to be printed. You can probably lookup MIME types for other file formats on Google.
     
ryanvp1
Fresh-Faced Recruit
Join Date: Feb 2007
Status: Offline
Reply With Quote
Feb 9, 2007, 02:34 PM
 
So I tried copying and pasting the code into AppleScript but when I try to save it I get an error message. I don't really know anything about Scripts. Could you explain to me how to make this script to print any attachments from my emails?? And also is there a way to make the script run automatically at a certain time of day, say 9 AM. So when I get to work my attachments are already printed out... Oh and if it helps my attachments are excel files...

Thanks
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 07:08 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,