Update: at some time since I built this script it has changed (by itself) within Hazel. I guess a Hazel update or an OS X update has prompted this. The difference is in the print line which now reads:
print theFile without «class pdlg»
Thanks to Kelly for alerting me to the fact the original wasn’t working.
If you listen to the Mac Power Users podcast, or perhaps you’ve heard Katie or David on other podcasts, then there’s a really good chance you’ve heard of Hazel. Hazel is a very powerful tool for automation and David and Katie often mention it as part of a solution to their problems.
In the latest issue of ScreenCastsOnline Magazine, Katie wrote about using Hazel to automatically upload files to Evernote. I guess I finally got overwhelmed with all the goodness of the paperless lifestyle and I went and bought Hazel. It’s a very modest USD$25 considering the power it has.
Now, despite the idea being to go paperless – eventually – a current reality is that my wife pays the bills and right now most of them arrive on paper. So one of the bills that arrives electronically usually gets printed in order for it to get paid. Yeah, I’ll work on that!
So I got to thinking – in the meantime, can I use the same techniques to automatically print a document? Turns out yes, I can. It’s pretty easy, too. When you know how! It took me a lot of Googling and experimenting to work out the correct Applescript to print a document. I’ll save you all the trouble. Here’s the code as shown in Hazel’s action panel.
I’ve put the text at the bottom of this post so you can easily copy and paste, too, but above shows the syntax highlighting that Hazel will show you when it compiles successfully.
The only thing you’ll need to change is the name of the printer where you want it to print. Make sure you get the name exactly right. If a window pops up and asks where your printer is, then you’ve got the name wrong. That “smart quote” in the name (for the possessive ‘s’) stumped me for about half an hour because I typed what I saw.
The easiest way to copy the exact printer name is to open the print queue for the printer (you can do this from the Print and Scan System Preference pane), then click on the Settings icon. The name is shown in an editable field from where you can copy it.
When the action runs, you will notice the print queue window open and then close. If it’s already open, it will still close. If you want the print queue window to always remain open, remove the quit line from the script.
Note that I have only tested this on PDF files. It may work for other file types, but you’ll have to find that out for yourself. Applescript allows for instructing specific applications to print their documents, but I will leave that as an exercise for the reader.
tell application "Your Printer Name Here" activate print theFile without print dialog quit end tell
Banner image from Wallpaper Converter by andreea.