Go Back   The macosxhints Forums > OS X Help Requests > AppleScript



Reply
 
Thread Tools Rate Thread Display Modes
Old 06-16-2012, 11:24 AM   #1
benwiggy
League Commissioner
 
Join Date: Aug 2006
Posts: 5,039
Print to print queue from Finder trouble

I'm trying to create a Service that will print the selected documents in the Finder, by launching them in their default apps and printing them to a specified print queue without opening the print dialog (i.e. no user input required).

Here's the AppleScript code in Automator:
Code:
on run {input, parameters}
	set NumFiles to count of items of input
	repeat with i from 1 to NumFiles
		set some_item to item i of input
		try
			tell application "System Events"
				print some_item with properties {target printer:"Direct PDF"} without print dialog
			end tell
		end try
	end repeat
	
	return input
end run
If I change the application tell to a specific app, like BBEdit, it works. Otherwise, I get nothing. (Though when it does work, it sometimes uses the default print queue, not the specified one.)

The only feedback I'm getting is:

16/06/2012 17:14:34.359 com.apple.automator.xpc.workflowServiceRunner: 2012-06-16 17:14:34.357 WorkflowServiceRunner[6801:1707] Could not connect the action buttonPressed: to target of class NSApplication

in the Console.

EDIT: Actually, I don't know how quickly the Services menu "updates" itself. I changed the name of a service and the change wasn't implemented after logging out and in again. Restarting the LS database seems to have really knackered things.

Last edited by benwiggy; 06-16-2012 at 12:20 PM.
benwiggy is offline   Reply With Quote
Old 06-17-2012, 07:39 AM   #2
anthlover
Hall of Famer
 
Join Date: Apr 2003
Posts: 2,662
What your doing sounds like more fun/interesting. But why not highlight the document and choose the Print option? It just prints and does not invoke the print dialog box.
anthlover is offline   Reply With Quote
Old 06-17-2012, 09:52 AM   #3
benwiggy
League Commissioner
 
Join Date: Aug 2006
Posts: 5,039
Quote:
Originally Posted by anthlover
But why not highlight the document and choose the Print option? It just prints and does not invoke the print dialog box.

Because that sends the job to the default (or currently selected) printer. I want the print queue to be determined by the Service.
Also, some apps DO show the print dialog when you do <Command> P in the Finder.
And there's a bug that affects printing from the Finder to Preview.
benwiggy is offline   Reply With Quote
Old 07-07-2012, 07:48 PM   #4
sojourner
Major Leaguer
 
Join Date: Apr 2010
Posts: 324
Found this on another website. Seems to work for RTF files. Wasn't able to get it to work with docx files.

Using -h flag gives some lists command options.

Code:
/System/Library/Printers/Libraries/convert -f file.rtf -o file.pdf -j "application/pdf"
__________________
see a problem; solve a problem.
sojourner is offline   Reply With Quote
Old 07-08-2012, 01:43 AM   #5
benwiggy
League Commissioner
 
Join Date: Aug 2006
Posts: 5,039
The convert command only works for file formats that OS X can handle -- e.g. stuff that Preview can open, Office formats, etc.

And while it does convert those files to PDF (which you've correctly noticed is the purpose of the print queue in my AppleScript), I'm looking for a general solution, as I want different Services for different print queues (or one big mother of a Service that can specify the print queue).

Last edited by benwiggy; 07-08-2012 at 01:48 AM.
benwiggy is offline   Reply With Quote
Old 07-08-2012, 03:12 PM   #6
mclbruce
Hall of Famer
 
Join Date: Mar 2002
Posts: 3,870
I'm just guessing, but here goes: when I go to System Preferences: Printers, and double click on my printer, it shows up in my dock. I can drag and drop any document to the dock icon and it shows up in the print queue. I have tried a few different types of files and I haven't seen any dialog boxes yet.

Now, when I click on the dock icon and go to the print queue window, then control-click on the title I see the queue is located in ~/Library/Printers. Opening that folder shows me the print queue icon with the suffix .app

So maybe your AppleScript could just open the selected file with the app that is the print queue. If you don't want to use the defaults for that print queue you could make another print queue in System Preferences, which would be a different app, and change the defaults for that one.
mclbruce is offline   Reply With Quote
Old 07-08-2012, 03:38 PM   #7
benwiggy
League Commissioner
 
Join Date: Aug 2006
Posts: 5,039
Quote:
Originally Posted by mclbruce
I'm just guessing, but here goes: when I go to System Preferences: Printers, and double click on my printer, it shows up in my dock. I can drag and drop any document to the dock icon and it shows up in the print queue. I have tried a few different types of files and I haven't seen any dialog boxes yet.

I get the app's dialog box with formats that aren't OS X native.
benwiggy is offline   Reply With Quote
Old 07-08-2012, 04:16 PM   #8
NaOH
Hall of Famer
 
Join Date: Dec 2007
Posts: 3,642
I'm guessing this won't appeal to you, benwiggy, but I'll put it out there in case that's incorrect. With Keyboard Maestro you could create a macro which executes your script and handles things without user input in the event that the print dialog appears due to the file type selected. This is based on a macro action Maestro has called If Then Else. In simple terms, by using this action you could configure things such that Maestro will handle what needs to be done if it's a file type which includes the print dialog. All told, you'd have a process that looks something like this:
  • Select the file(s) and activate the Maestro macro using whatever shortcut you assign (you could even have a palette appear allowing you to choose variations on your script based on the printer you'd like used).
  • The macro would run your script.
  • After a prescribed time delay, Maestro could be told to see if there is a Print button. If yes, Maestro could then press that button, else Maestro could do nothing (since the script presumably handled everything on its own).

If that approach is even a consideration for you, Keyboard Maestro offers a 30-day trial. If you try it and need any help configuring the macro, I'd be happy to help.
NaOH is online now   Reply With Quote
Old 07-09-2012, 01:34 AM   #9
benwiggy
League Commissioner
 
Join Date: Aug 2006
Posts: 5,039
I do use iKey, which is a similar thing to Keyboard Maestro.

Thanks for the various ideas, but I was hoping to create the Service to work on any Mac.

I might look at another way of doing it, as it does seem that there is variation across different app's handling of the print applescript command.
benwiggy is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting 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

Forum Jump



All times are GMT -5. The time now is 03:24 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.