7 Replies Latest reply on Jan 26, 2010 12:37 PM by WoodApple

    Printer automation progress . . . perhaps



      Printer automation progress . . . perhaps


      I've been thinking about this for a while and I'm making some progress. I'm trying to set up, with some success, a system of automating printer selection and printing. So far I'm using Terminal commands to list and select printers, and I've set up a printing preferences file in which the user chooses various printers for different tasks. There's one awkward (?) bit so far which involves reading or copying a text string (printer_name) from a terminal window, but at least the user is informed as to how exactly the system (Mac OS X 10.6.2) sees the spelling of the devices. I'll likely find a way to automate this and do away with this user interaction. However, now I realize I'm going to have to dispense with the "Print" script step since there's no way to use it without a printer choice and the step overrides the OS level choice that's already been made. I can see my way clear to printing directly from the OS with a bit of work. My question is this (I have nearly NO knowledge of Windows OS): am I painting myself into a "Mac only" scenario? I'm being careful to use only commands recognized by CUPS but does that mean anything in the Windows world? Since it's an acronym for Common Unix Printing System (I think) I suspect Windows doesn't use it.


      So far, with the above-mentioned exception, the process is invisible and fast. The user is presented with a selection of common tasks . . . this is only done once . . . such as General, Cheques/Preprinted Forms, Color, Labels and Envelopes. Each task can be assigned a printer. Several tasks can share a printer and up to five different printers can be assigned. Each print script sets a variable "$PRINTER" to the appropriate device. If there's only one printer connected all tasks are assigned the same device. A Terminal shell script (via calculated Applescript) then sets the destination printer.The user can also choose to view the print dialogs in the Print Preferences although there's not much point.


      Anyway, as soon as I replace the Print script step with an OS level shell script, I believe I'll have automated printer selection that's portable and doesn't require a plug-in.


      I know Windows doesn't use Applescript but surely has something comparable. It's the CUPS part that concerns me.





        • 1. Re: Printer automation progress . . . perhaps

          To provide a context to my previous post, and possibly to elicit response, I'd like to explain the issue I have with Filemaker's scriptable printing capabilities.


          I, and I'm sure countless others, require a solution to do a lot of printing. In my case this involves mainly cheques, contracts and envelopes. Being able to script all these tasks is a major factor in favor of using FM. On my own setup all the printing works flawlessly. However I'm looking to expand my business a bit and am considering allowing my solution to be used by an associate or two. Of course he/she doesn't have the same printers, so I'm developing a routine that will dynamically set up printers based on User Preferences.


          This issue is a "black hole" (to me) in FM. Printing should be scriptable independent of the printers connected to a given machine and FMI should have thought of this a long time ago.


          As I've said, this issue is going to be resolved in my particular solution one way or the other. Any suggestions or comments are more than welcome! 

          • 2. Re: Printer automation progress . . . perhaps

            It is a weakness I have long viewed by Filemaker.  Back when I used version 4, I would create a record for a new member.  When the record was complete I had to

            print a plastic ID card, a welcome letter, and the envelope.  I found a plug-in that worked for me on Win95 (ok years ago).  But it worked and it did so very well. 



            • 3. Re: Printer automation progress . . . perhaps

              Not sure of the exact behavior on a mac but...

              on windows using the print script step without dialog will cause whatever to be printed to print to whatever the defualt printer was at the time filemaker was opened. I have scripted printing to various network printers by using a os level script to create/change the defualt printer and updating the value in the registry, after which filemaker will print to the printer I had choosen, without dialog. (the printers names are stored in a filemaker file and passed to a vbs script created by calculation and exported from a field with the option to open it, causing the script to run.)


              Printing from filemaker has always been more of a challenge than it should be.

              • 4. Re: Printer automation progress . . . perhaps

                Thanks for the replies. Yes, WoodApple, that's similar to what I'm doing on Mac. I'm changing the destination printer on the OS level, and I've found a way to in effect replace the Print script step with OS level scripting except for one detail in the print dialog: "current record" or "records being browsed". If I can't address it directly I'll automate the print dialog, as I've done several times, to save as pdf to a temp folder, print the pdf with an OS script, and then delete the pdf from the temp folder(also OS scripting). Seems like the long way around but, if written properly, it will blaze along all the same.



                • 5. Re: Printer automation progress . . . perhaps
                     Would you mind sharing the script with us?
                  • 6. Re: Printer automation progress . . . perhaps
                       Rick, would you mind sharing the vbscript?
                    • 7. Re: Printer automation progress . . . perhaps

                      Set Variable [ $VBS; Value:"Set WshNetwork = CreateObject(\"WScript.Network\")¶ set WshShell = CreateObject(\"WScript.Shell\")¶ Set oPrinters = WshNetwork.EnumPrinterConnections¶ Dim WshShell, WshNetwork, BtnCode, printthere, iprinter¶ iprinter = \"no\"¶ Serv = " & $Serv & "¶ Printer1 = " & $Printer & "¶ ver = " & $Ver & "¶ PrIP = " & $PrIP & "¶ 'WScript.Echo Serv¶ If Serv = WshShell.RegRead (\"HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\ComputerName\ActiveComputerName\Computername\") Then¶ printthere = Printer1¶ Else¶ printthere = (\"\\\\\" & Serv & \"\\\" & Printer1)¶ End If¶ For i = 0 to oPrinters.Count - 1 Step 2¶ if oPrinters.Item(i+1) = printthere THEN iprinter = \"yes\"¶ Next¶ IF iprinter = \"yes\" THEN¶ 'WScript.Echo \"Printer installed \" & iprinter¶ ElseIF iprinter = \"no\" THEN¶ WshNetwork.AddWindowsPrinterConnection Printthere¶ END if¶ WshNetwork.SetDefaultPrinter Printthere¶ WshShell.RegWrite (\"HKEY_CURRENT_USER\Software\FileMaker\FileMaker Pro\\\" + ver + \"\Preferences\printer\"),printthere + PrIP,\"REG_SZ\"¶ WScript.Quit" ]

                      This is the Set variable script step I use to create the script,


                      Set Field [ Prt.Printers::VBS; $VBS ] Export Field Contents [ Prt.Printers::VBS; “$$ScriptPath”; Automatically open ]




                      I then set a field with this and export field contents (automaticlly open) to run it. You can also use

                      If [ (Get ( PrinterName ) = "\\\\" & Prt.Printers Values::PrinterServer & "\\" & Prt.Printers Values::Printer_Name & Prt.Printers Values::Printer_Options) ]


                      or something like that to test if it happened.(can only tell after a print setup script step)