4

On MacOS, you can drop a PDF directly onto the window of a Printer's print queue, and it will be sent to print immediately (with the printer's default settings).

I'm looking for a way to do a similar thing with a specified folder. E.g. Any PDF or PostScript file dropped onto that folder (or saved there through any other method) will be sent straight to the printer.

The obvious thing is to use Folder Actions and an AppleScript, but I'm wondering if there's a neater solution that I've overlooked? Essentially, I'm looking for a filepath that works as a print queue.

8

There is a simpler solution in 4 steps and a small shell script:

  1. make your own spool directory:

    /usr/bin/sudo mkdir /var/spool/my_printer
    
  2. write the following shell script within your usual local bin directory let's say /local/bin

    cd /local/bin
    

    copy the following inside my_spooler:

    #!/bin/sh
    
    # go into the spool directory
    cd /var/spool/my_printer
    
    # main loop: loop till end of time
    while : ; do
    
        # check for any newly arrived text file
        for _file in * ; do
    
           # if _file is a normal file, print and remove it (-r option to lpr)
            [ -f "${_file}" ] && lpr -r "${_file}"
        done
    
        # don't loop like a fool
        sleep 300
    done
    
  3. make your my_spooler executable:

    chmod u+x my_spooler
    
  4. start it:

    my_spooler &
    

    it should start without a full path if /local/bin is within your PATH if it isn't, then start it this way:

    /local/bin/my_spooler &
    

    The ending & means start it in background so as not to block your session waiting until the end of time.

How to use it

To use it you simply have to move any text or PS or PDF file within your own defined spool directory how you prefer. Either with the Finder or with basic command line:

cp my_file.pdf /var/spool/my_printer
  • Shell script not yet checked. If it's working just send me a 😀. – dan Jan 26 at 12:33
  • Thanks. This is part of a larger project, so I'll let you know when it bears fruit, but it looks good. – benwiggy Jan 26 at 18:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .