Automatically Print Attachments in Apple Mail
Mar 14, 2008
Having spent hours scouring the Internet for someone who had already solved the problem of "how to automatically print attachments from Apple Mail," I found no answers. In fact the following Google Search "print attachments" apple mail applescript yielded only 7 results on October 7, 2007.
In my case the reason I wanted to do this is that I get my faxes sent to my email from an online fax service. I currently use Send2Fax.com, but have used eFax in the past. The faxes are sent to a separate email account I have set up specifically to receive faxes. Then I have to open the message, open the attachment, and print. Very redundant. My laziness demands an easier way.
I searched the forums. Automator actions and workflows, Applescript resources, etc.
After stepping back a little I started thinking along new lines. How about I save the document what are my options then? I came up with a jury rigged method of using folder actions along with auto saving of the attachments.
I made a destination folder, and attached an applescript to it to try and print the document with Preview. However to my utter surprise I found out that Preview is not scriptable.
Hours more spent in trying to figure out how to make Preview scriptable came up with the following command to enable the Standard Suite for Preview:
defaults write /Applications/Preview.app/Contents/Info NSAppleScriptEnabled -bool YES
However this still didn't solve my problem.
Then I remembered years ago discovering that PDF files can be printed from the command line using "lp" a little command line utility for printing inside a terminal shell.
I am not going to go into that here, but that is the only thing that was able to get me moving back in the right direction.
I found a script in my system library for saving images as a JPEG which I altered to simply use "lp" to send the document to my printer.
Then I found a script here:
That I altered to save my attachments automatically for me in the folder with my action attached to it and bam! My faxes now print automagically.
You could use this for any file that can be printed with "lp".
The Steps are:
- I created a folder for my faxes:
- ~/Faxes
- I right clicked on the folder to enable folder actions as explained here
- Then I saved this script in "~/Library/Scripts/Folder Actions"
- This was a script I modified from the provided folder action "Image Ð Duplicate as JPEG.scpt" which you can find at: "/Library/Scripts/Folder Action Scripts"
- And then attached this script to the folder using the above instructions.
- Next I saved this script in "~/Library/Scripts/Applications/Mail/"
- This is the script I modified from here
- Then came the set up in Apple Mail.
- I created a rule:
- All conditions met
- Any Attachment Name - Contains - ".pdf"
- Account - myfaxaccount@faxaddress.com
- Run Applescript - "~/Path/to/script"
- http://webscripts.softpedia.com/
- http://www.tikouka.net/
- http://the.taoofmac.com/
- http://www.slamslash.com/
- http://www.simplehelp.net
- http://search.techrepublic.com.com
- http://www.scriptbuilders.net
- http://www.schartworks.com
- http://www.merzwaren.com
- http://www.mailsteward.com/
- http://www.macworld.com
- http://www.macwindows.com/
- http://www.macupdate.com
- http://www.macresearch.org
- http://www.macosxhints.com
- http://www.macosxhints.com
- http://www.macosxhints.com
- http://www.macosxhints.com
- http://www.macosxhints.com
- http://www.macosxhints.com
Update
The problem is that line 45 should read like this:
if (every mail attachment of theMessage) ≠ {} then
the not equal sign is not showing up in the text.
I have placed a copy of the script in script editor format here.
Filed under: /applescript






Whether you're just grilling, picnic lunching or heading out on a wilderness excursion for the holiday weekend, we've got a few recipes, projects, and ideas to run by you, cultivated from years of gathering clever outdoor hacks.










