Printing without dialog to automate emailing PDFs

I have been scouring threads without making any progress on this subject.

I am looking for a script that will shortcut the print dialog progress, irrespective of what application the print dialog is invoked in. The reason for this is that I have set up a virtual printer to print whatever I am working on into PDF format inside a specified folder. That folder has a folder action which sends new items to Entourage. The idea is to be able to generate an email with the PDF as an attachemwnt. The missing link is a script (to which I can assign a hotkey) which will print whatever I am working with using the virtual printer that I have set up (preferably leaving the default printer settings intact). At the moment I have to manually invoke the print dialog in whichever application I happen to be in, select the virtual printer (which annoyingly then becomes the default printer) and hit enter.

So far, I have cobbled together the following:

tell application "Printer Setup Utility"
	set defaultprinter to current printer
	set current printer to printer "Email PDF"
end tell

tell application "System Events"
	keystroke "p" using command down
	key code 36
end tell
delay 10

tell application "Printer Setup Utility"
	set current printer to defaultprinter
end tell

But it is rather clunky and unreliable, particularly in resetting the default printer back after it has been invoked. I would prefer a solution that operates directly on the print dialog, without needing to resort to GUI manipulation and without needing to tamper with Printer Setup Utility and the default printer prefs.

Does anyone know of a solution or have any suggestions?


Model: PowerMac
AppleScript: Latest
Browser: Safari
Operating System: Mac OS X (10.4)

Gidday kiwilegal

do you mean something like this?

tell application “Adobe Illustrator”
set myFile to “Macintosh”
print file myFile
end tell

Hi Budgie

Not quite. I am looking for a script that is application agnostic (ie does not care what application I am in). The script needs simply to print (without going through the manual steps normally required using the Command P - print dialog route).


You could use lpr


I would also like something along the same lines just that when someone uses the “apple + p” it automatically prints to default printer

I have been searching high and low for the answer to this,

Thank you

Model: G5 Quad
AppleScript: 1.0
Browser: Firefox
Operating System: Mac OS X (10.4)


So how would lpr work? Is it some sort of UNIX command? Needs a shell script?

Sorry, I am not technically proficient…

Just want to print to printer I have called “Email PDF”…


Yes, lpr is a UNIX command, and it works best with PDF files that just need to be printed. Here is a handler that I use:

to printFile(b)
    set Print_er to "Deskjet_5400_series" 
    set file_to_print to POSIX path of (b as Unicode text)
        do shell script "lpr -P " & (quoted form of Print_er) & " " & (quoted form of file_to_print) --Prints paystub to identified printer
    end try
end printFile

You need to address the printer by name, and you can find the name of your printer (as UNIX sees it) by going to the Terminal and entering this text:

lpstat -a

Which will generate something like this:

Deskjet_5400_series accepting requests since Jan 01 00:00

Then, just copy the name of the printer over to the hander (set Print_er to “Deskjet_5400_series”) and it should work. The variable b is a path to the desired PDF file, and this handler will convert it to the proper UNIX path for the do shell script.

I hope this helps,

Thanks, Craig.

I had found another thread with your post on this subject but it doesn’t do quite what I am seeking to achieve.

I am looking to emulate the command P print function. So, for example, I am in Safari and I come across a web page I want to email in PDF format. At the moment, I use my rather kludgy solution set out at the beginning of this thread to print the web page to my Virtual_Printer. It works but is not elegant. Same process if, for example, I want to email a PDF version of an open Word document that I am working on. No need to print as PDF then attach to an email (requiring several clicks and delving down into sub menus). All done with the press of a button.

Your code works well if you want to print a known saved file. But in the workflow I am describing, it is the open document/web page that is the target. So I am not sure if your routine can be adapted for this purpose, or whether lpr is suitable for such a routine.

Your help so far is much appreciated.