lp
is able to read data from standard input, see man lp
:
lp submits files for printing or alters a pending job. Use a filename of "-" to force printing from the standard input.
So if you followed the advice given in the referenced question to install a "raw" printer you should be able to run
echo "whatever text you want to print" | lp -d Generic_usbtb -
After noodling on this question and worrying that my google-fu had atrophied, I sorted out something that works.
Edit the generic PPD file provided in Mac OS X to add the desired page size. I found the generic PPD file here:
/System/Library/Frameworks/ApplicationServices.framework/Frameworks/PrintCore.framework/Resources/Generic.ppd
Follow the directions here https://stackoverflow.com/questions/1028891/whats-the-easiest-way-to-add-custom-page-sizes-to-a-ppd to figure out what needs to be added. (Thanks, SO). In my case, the lines added were (they are non-contiguous in the file, just look to see where they go):
*PageSize LetterEx/US Letter Expanded: "2 dict dup /PageSize [630 810] put dup /ImagingBBox null put setpagedevice"
*ImageableArea LetterEx/US LetterExpanded: "18 18 612 792 "
*PageRegion LetterEx/US Letter Expanded: "2 dict dup /PageSize [630 810] put dup /ImagingBBox null put setpagedevice"
*PaperDimension LetterEx/US Letter Expanded: "630 810 "
Edit the generic PPD file to set the new settings as the Default in each case. This seemed to be necessary in make case to get the desired PS output. Note these are also non-contiguous in the file, but just replace them where each *Default occurs.
*DefaultPageSize: LetterEx
*DefaultImageableArea: LetterEx
*DefaultPageRegion: LetterEx
*DefaultPaperDimension: LetterEx
Reboot the system. For whatever reason, my attempts to restart the printing system/CUPS/whatever didn't take.
Install a new printer, type IP, IP address = localhost or 127.0.0.1, and specify the Generic Postscript Printer type.
From your application (in my case, Word or Pages) do Print, select the 127.0.0.1 printer, select the Letter Expanded page size for your target document page size, and then do PDF/Save as Postscript. It appears that the Postscript conversion engine silently makes use of the current printer profile when producing the PS, rather than the application's page size settings.
Best Answer
You don't need to create a "driver" as the functionality you need is already available. From the normal Print (CMD+P) dialog window, in the lower left corner, click on the PDF drop-down menu and choose the Save as PostScript option to save the "print" as a .ps file. (This part may have been your step #1 but I wasn't sure how you were saving the page as .ps)
Using a macro/script utility like Hazel, Keyboard Maestro, Automator, etc., they could be configured to monitor a specific folder where you save the .ps file. When a new file appears, the macro/script could trigger to send the file to the printer.
Also, depending on the printer model, it is likely the script could send the .ps file directly to the printer using a port/interface designed for a script/stream instead of using the web GUI. IPP/LPD/socket interfaces are designed for exactly this. Most likely the web GUI is using a javascript to grab the file from you then pass it into one of these interfaces.
P.S. Notice that in the screenshot, the "Save as PDF" option has a CMD+S shortcut. I created that by using the Keyboard Preference Pane in System Preferences. If you want to do the same but for the "Save as PostScript" option... Open the Keyboard Preference, switch to Shortcuts, select App Shortcuts on the left then click the [+] icon below. Set the shortcut for All Applications, Menu Title of "Save as PostScript...", and the Shortcut as CMD+S. You can use CMD+S because the normal shortcut for CMD+S (File>Save) is not available when the Print dialog is shown. Another good shortcut is CMD+P for the same reason. That way you press CMD+P, wait a second for the dialog to appear, then press CMD+P again.