Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

happygodavid

macrumors 6502
Original poster
May 14, 2007
251
265
Northern Virginia
Hi all,

Not sure where to post this...

What I need to do:

I often have a ton of pdf documents opened up in Preview, and to print them all off, I have to click on each open document and print it as an individual file. Is there any way to have Automator do this for me? Press a button and BAM, all open documents for a particular application will print. Or perhaps an Applescript? (Heck, I don't even know if that's what Applescript is for; just wondering if that's a solution.)

Is this possible? If so, how do I go about doing it?

Thanks in advance!

I'm running Mavericks, btw.
 
You're doing things the hard way. Print your files from the Finder directly - it's what I do to dozens of documents I've already proofed. No Automator or AppleScript necessary.

  1. Open System Preferences
  2. Select Printers & Scanners
  3. Select your printer in the Sidebar
  4. Click the “Open Print Queue...” button.
  5. The Printer will now show up in the Dock
  6. Control-click on the Printer icon in the Dock
  7. Select Options > Keep In Dock.
In the Finder, drag your files one at a time or all of them to the new Dock icon for your printer. QED. BTW, make sure you have enough paper in the tray... :eek:
 
You're doing things the hard way. Print your files from the Finder directly - it's what I do to dozens of documents I've already proofed. No Automator or AppleScript necessary.

  1. Open System Preferences
  2. Select Printers & Scanners
  3. Select your printer in the Sidebar
  4. Click the “Open Print Queue...” button.
  5. The Printer will now show up in the Dock
  6. Control-click on the Printer icon in the Dock
  7. Select Options > Keep In Dock.
In the Finder, drag your files one at a time or all of them to the new Dock icon for your printer. QED. BTW, make sure you have enough paper in the tray... :eek:

Thanks for the suggestion! That's a great idea (and I'll use it in other instances), but I'm wondering if there's any way to do this with files that are already opened. Reason being, I'm opening up a bunch of documents to view them before printing them. I end up with a screen full of pdf's, then I want to print the ones I have open. Any other ideas?
 
Any other ideas?

Why yes, yes I do.

Open your 22 (or 9?) documents in Preview - all at the same time. Select them in Finder - I open multiple PDFs simultaneously by selecting what I want in one or more Finder windows. Remember, Shift-Click and Command-Click are your friends here to select contiguous and non-contiguous files - then use Command-Down arrow (on your keyboard) to open the PDFs (or JPEGs or other Preview-compatible files) at the same time.

Now that you have all of your files open in one window select the Thumbnails option from the View menu. You'll see thumbnails of all of your open files in the Sidebar. You'll be able to use selection commands with the keyboard and/or mouse to select which - or all (Command-A) pages you want active.

Once you have some or all of the pages actively selected in the Sidebar - choose the Print Command (Command-P) - all of the pages you've selected in the Sidebar will show up in your Print Dialog box. QED.
 
Thanks for your ideas, campyguy! Also another great suggestion.

Perhaps I'll give another detail, and you may have another trick up your sleeve. :)

So, basically, I'm a musician, and I'm using a website that stores pdf's of music I'll be using for upcoming gigs (the reason for this is so the other musicians can have access to the site/song order/mp3's, etc.). When I'm picking music, I click the songs on the site, and a pdf gets downloaded to downloads, and the pdf opens. (So I'm not opening them from Finder; they just open.) I'll look at all the charts I've got open, make sure they're what I want, and then print the ones I've settled on. I could just close the files then reopen them from downloads using your method, but I feel like there has to be a quicker way. Thanks again for your help!
 
AFAIK, the Mac Preview application isn't scriptable for print-related items. I use Acrobat Pro and Automator when I need them.

If I were you, I'd be saving those items you want to keep to a folder/directory - I use Default Folder X to speed that kind of action up, a massively powerful extension to the Mac I've been using for over a decade. IOW, as you're reviewing your toss-vs-keep files, put all of your keep files in a folder for printing later (or some future date/time).

What I'd do then is drag all of those files - in the Finder - to the Desktop printer (in the Dock, I know...). You're saving those PDFs you want to keep anyway, right? The Finder is scriptable, but this is easy, and a simple extension to your existing workflow (DL files, save them someplace, that's pretty much it...).

I recommend checking out Default Folder - it's not cheap, but it's so freaking powerful and so much cheaper than therapy!
 
I could just close the files then reopen them from downloads using your method, but I feel like there has to be a quicker way. Thanks again for your help!

Try this :

Create a Service in Automator

  1. Service receives no input in any application
  2. Run AppleScript action with the following code :

    Code:
    on run {input, parameters}
    	
    	(* Your script goes here *)
    	tell application "Preview"
    		set documentPaths to path of every document whose name ends with "pdf"
    	end tell
    	
    	if documentPaths is not {} then
    		return documentPaths
    	end if
    	--return input
    	
    end run
  3. Print Finder items action
  4. Save the service e.g. PrintOpenPreviewDocuments

Run your Service from the Preview Services menu.

Note : As I don't have a printer I've only done some quick testing on Mavericks with a Generic PostScript Printer.
 

Attachments

  • Screen Shot 2014-10-21 at 06.17.01.png
    Screen Shot 2014-10-21 at 06.17.01.png
    49.4 KB · Views: 301
  • Screen Shot 2014-10-21 at 06.18.14.png
    Screen Shot 2014-10-21 at 06.18.14.png
    50.5 KB · Views: 285
  • Screen Shot 2014-10-21 at 06.19.58.png
    Screen Shot 2014-10-21 at 06.19.58.png
    89.7 KB · Views: 294
Kryten2, you are the man! This is EXACTLY what I was looking for. Worked perfectly the first time! Thanks for taking the time to figure this out and respond.

Now, I can have a ton of documents open in Preview, click Preview>Services>PrintOpenPreviewDocuments, and BAM, they all print.

Thanks again.

Try this :

Create a Service in Automator

  1. Service receives no input in any application
  2. Run AppleScript action with the following code :

    Code:
    on run {input, parameters}
    	
    	(* Your script goes here *)
    	tell application "Preview"
    		set documentPaths to path of every document whose name ends with "pdf"
    	end tell
    	
    	if documentPaths is not {} then
    		return documentPaths
    	end if
    	--return input
    	
    end run
  3. Print Finder items action
  4. Save the service e.g. PrintOpenPreviewDocuments

Run your Service from the Preview Services menu.

Note : As I don't have a printer I've only done some quick testing on Mavericks with a Generic PostScript Printer.
 
Actually, hang on... I just tried this with 20 Preview documents, and it only printed 5 random ones. Any idea on how to make it print all of them?

Thanks again! So close to having this new weapon in my menu bar.

Try this :

Create a Service in Automator

  1. Service receives no input in any application
  2. Run AppleScript action with the following code :

    Code:
    on run {input, parameters}
    	
    	(* Your script goes here *)
    	tell application "Preview"
    		set documentPaths to path of every document whose name ends with "pdf"
    	end tell
    	
    	if documentPaths is not {} then
    		return documentPaths
    	end if
    	--return input
    	
    end run
  3. Print Finder items action
  4. Save the service e.g. PrintOpenPreviewDocuments

Run your Service from the Preview Services menu.

Note : As I don't have a printer I've only done some quick testing on Mavericks with a Generic PostScript Printer.
 
Worked perfectly the first time!

How many documents were printed on the first time?
Actually, hang on... I just tried this with 20 Preview documents, and it only printed 5 random ones. Any idea on how to make it print all of them?

Thanks again! So close to having this new weapon in my menu bar.

It should print all of them. They all are PDFs and their name ends with pdf? I'll do some testing and will edit my post but I'm afraid that's all I can do.

Can you try this :

Replace the code in the first Run AppleScript action with this :

Code:
on run {input, parameters}
	
	(* Your script goes here *)
	tell application "Preview"
		set documentPaths to path of every document whose name ends with "pdf"
		set documentNames to name of every document whose name ends with "pdf"
	end tell
	
	log_event("PrintOpenPreviewDocuments Service Log", true)
	log_event("Number of open Preview documents : " & (count documentPaths), true)
	log_event("Names : " & return & "=========================", true)
	set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
	log_event((documentNames as string) & return & "=========================" & return, false)
	set AppleScript's text item delimiters to ASTID
	--log_event("")
	if documentPaths is not {} then
		return documentPaths
	end if
	--return input
end run

on log_event(theMessage, addDateStamp)
	try
		if addDateStamp then
			set theLine to (do shell script ¬
				"date  +'%d-%m-%Y %H:%M:%S'" as string) & " " & theMessage
		else
			set theLine to theMessage
		end if
		do shell script "echo " & quoted form of theLine & " >> ~/Desktop/PrintOpenPreviewDocuments.txt"
	on error logError
		display dialog "Log Error: " & logError & return & return & "Message: " & theMessage
	end try
end log_event

Add another Run AppleScript action after the Print Finder items action with the following code :

Code:
on run {input, parameters}
	
	set documentNames to {}
	repeat with i from 1 to count of input
		set aName to item i of input
		tell application "Finder" to set end of documentNames to name of aName
	end repeat
	
	(* Your script goes here *)
	log_event("Documents received as input from Print Finder items action", true)
	log_event("Number of output documents from Print Finder items action : " & (count input), true)
	log_event("Names : " & return & "=========================", true)
	set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
	log_event((documentNames as string) & return & "=========================" & return, false)
	set AppleScript's text item delimiters to ASTID
	
	--return input
end run


on log_event(theMessage, addDateStamp)
	try
		if addDateStamp then
			set theLine to (do shell script ¬
				"date  +'%d-%m-%Y %H:%M:%S'" as string) & " " & theMessage
		else
			set theLine to theMessage
		end if
		do shell script "echo " & quoted form of theLine & " >> ~/Desktop/PrintOpenPreviewDocuments.txt"
	on error logError
		display dialog "Log Error: " & logError & return & return & "Message: " & theMessage
	end try
end log_event

Run the Service and look for a file on your Desktop named PrintOpenPreviewDocuments.txt. Number of documents and names should be the same. Attach the file to your post.
 

Attachments

  • PrintOpenPreviewDocuments.jpg
    PrintOpenPreviewDocuments.jpg
    504.5 KB · Views: 298
Last edited:
Sorry for the delayed response. It's crazy with my job around the holidays. Thanks for your continued help.

I changed the service using the edited scripts you suggested, and it still only prints 5 documents (I *believe it's the 5 docs that are on top of the pile).

Attached is the file that showed up on my desktop after running the service.

Thanks again!
 

Attachments

  • PrintOpenPreviewDocuments.txt
    978 bytes · Views: 163
Looking at the log there were 8 open Preview documents and 8 documents passed through the Print Finder items action. Why it prints only 5 is a mystery.
What exactly do you mean with the 5 docs that are on top of the pile? How many documents do you see in the print queue window when you run the service?
Can you post a screenshot of the print queue window when you run the service?
A screen recording would be even better. You can create that with QuickTime Player. If it gets to big to attach to your post maybe you can upload it to somewhere were I can download it.

Here's a screenshot of the print queue window when I ran the service with 8 open Preview documents.

Note : Do you see anything unusual in the Error Log?
 

Attachments

  • Screen Shot 2014-12-13 at 01.34.48.png
    Screen Shot 2014-12-13 at 01.34.48.png
    103.6 KB · Views: 267
  • Screen Shot 2014-12-13 at 01.35.53.png
    Screen Shot 2014-12-13 at 01.35.53.png
    26 KB · Views: 412
Looking at the log there were 8 open Preview documents and 8 documents passed through the Print Finder items action. Why it prints only 5 is a mystery.
What exactly do you mean with the 5 docs that are on top of the pile? How many documents do you see in the print queue window when you run the service?
Can you post a screenshot of the print queue window when you run the service?
A screen recording would be even better. You can create that with QuickTime Player. If it gets to big to attach to your post maybe you can upload it to somewhere were I can download it.

Here's a screenshot of the print queue window when I ran the service with 8 open Preview documents.

Note : Do you see anything unusual in the Error Log?
Sorry for not being more clear. By "5 docs on top of the pile," I mean the five docs that are in the foreground. How else can I explain what I mean...? Imagine a stack of paper. The top 5 sheets of said stack. So, Preview has a bunch of documents open, they are "in a pile/stack," and the top five "sheets" are the ones that go to the print queue.

I did a Quicktime screen recording and uploaded it to Dropbox. Here's the link: https://www.dropbox.com/s/4fuwea2tqbzfezy/Print%20all%20open%20docs.mov?dl=0

As you'll see in the video, there is a Console error that seems like it could have something to do with what's going on, but the strange thing is the date on the error. I'm not familiar enough with Console to decipher it.

Thanks again for your help!
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.