View Full Version : printing from shell to print center?
corvus
01-30-2002, 09:01 PM
Is there a command-line way to print to the printers that are defined in Print Center?
In other words, does lpr (or equivalent command) hook into the core OS X printing mechanism?
thanks.
Novajo
01-31-2002, 10:40 AM
It seems to me your only option is to make an AppleScript that prints a single file and make an alias in your shell to call the script with the file you are trying to print. You could use something along the lines of:
tell application "Finder"
set theFile to "/something/somewhere"
print (POSIX file theFile) as alias
end tell
and maybe piping it to osascript. I think you have to go through the finder and the related application. Therefore, if anyway you have to open an application, you might as well do it in AppleScript.
corvus
01-31-2002, 10:52 AM
Thanks for the reply.
When you say shell alias, I assume you mean a csh type alias, like you might put in a user's .cshrc file. Is that right?
And regarding your AppleScript, parts of this line puzzle me:
print (POSIX file theFile) as alias
I get everything up to the 'as alias' part. What does it mean to print somefile as alias?
I'll give this solution a try when I can. Don't have OS X at my disposal right now.
Novajo
01-31-2002, 01:38 PM
Yes, put the alias in .tcshrc
I believe it is:
print (this)
where "this" is ((POSIX file "/whatever") as alias).
Printing the file in the finder is the same as opening the application and printing.
I am not sure though. Anyway, if that does not work, remove alias. Take a look at the Finder AppleScript dictionary in Open Dictionary... of Script Editor.
bobsedge
02-15-2002, 03:35 AM
Check out /usr/sbin/Print
It works for me....
corvus
02-15-2002, 10:05 AM
Thanks bobsedge.
I wasn't able to get /usr/sbin/Print to work for me. Here's what I've tried:
% echo "Hello" > /tmp/test.txt
% /usr/sbin/Print -PLW8500EX /tmp/test.txt
[ 1 pages * 1 copy ] left in /private/tmp/502/Temporary Items/test.txt.ps
ERROR: Unable to print.
%
LW8500EX is my printer's name as it shows up in Print Center and
So that's it. Not a very descriptive error message, and nothing related shows up in any /var/log/* file.
However /var/spool/printing/ServerLog has a bit more detail in it, but nothing that tells me what the problem is:
<key>com.apple.printing.ErrorCode</key>
<integer>-50</integer>
<key>com.apple.printing.ErrorText</key>
<string>Invalid parameter</string>
<key>com.apple.printing.EventCode</key>
<integer>4001</integer>
<key>com.apple.printing.EventText</key>
<string>Error occurred</string>
Anyone got any ideas? I may post this over in the Apple forums now that I have more details.
Thanks!
bobsedge
02-15-2002, 07:55 PM
I had only tried printing PS files. If I try to print text files I get the same result as you.
Also, I tried
"""
cp /private/tmp/502/Temporary Items/test.txt.ps .
Print test.txt.ps
"""
And this worked. Odd, huh?
Maybe Print doesn't like the space in "Temporary Items"?
Let me know if you figure this out....
corvus
02-15-2002, 09:43 PM
I can't print postscript files either, regardless of the path I give to Print (i.e. fully qualified path or not).
I'm about to replace linux on my powerbook with OS X, so once I finish that, I'll test the Print command again.
Thanks for trying things out on your end for me. I did post on apple's forums in the Print Center message board so if something conclusive comes up, I'll relay it back to this forum.
Take care.
Dr-NiKoN
02-16-2002, 03:07 PM
I don't see how this is a better solution than lpr. Using this Applescript you can't choose what printer to print from.
Another option might be to wright a shellscript that parses ~/Library/Preferences/com.apple.print.PrintCenter.plist, not sure if this is possible though.
nikon
Using the -P option it should be possible to specify the printer, and using the -M option it should be possible to to specify the file type--postscript, text or other.
type 'man Print'
Nate
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.