Scripting Printer Changes (Mac)
By Scott G. Howard (scottgh@mindspring.com)
BONUS FILE: XCMD OSAX & PRINT.FP3
PLATFORM: Macintosh Only
[Editorial overview] This article covers printing to various paper trays found on one printer. The article should be of interest to Macintosh users with multiple trays attached to their printers. (MP)
You've just finished an awesome summary report your users can generate with the click of a button. Behind the scenes you worked your scripting and calculation magic so they aren't bothered with finding, sorting, the layout or mode switching and window zooming. When a user clicks "Continue" or hits the enter key, he or she is given the opportunity to print the report, continue viewing the report, or go back to the previous layout. All nicely automated, until someone prints to a printer that contains letterhead in the default paper tray - expecting a different paper source to be used. This scenario happens when printing without the print dialog box. When the print dialog box is deactivated in the Print script step, FileMaker Pro prints to the last printer and paper tray specified on the user's Macintosh.
Since FileMaker Pro cannot save paper tray selections in a script, you might present the user with a message prompting to "Select the 500-sheet paper tray in the print dialog box that follows the message." The problem becomes more acute if your script needs to print, say, a summary report from the 250-sheet tray, a form from the 500-sheet tray and an envelope from the multipurpose tray. Users must manually select the correct paper tray for at least two of these options. So much for elegance.
You could automate this with QuicKeys, but there's a nice solution using AppleScript and a copy of your LaserWriter driver, although slightly altered by ResEdit (Apple's infamous resource editor. However, don't let this frighten you - this is really not a difficult solution, so stay with me.) Assuming you are very familiar with the Macintosh environment, I'll move through this solution, so if something needs more explanation feel free to email me.
Let's take the scenario above to illustrate our solution. The printer in use will be a LaserWriter Pro 630 named "LabPrinter" on your network. With one button your users will print a report to the 250-sheet cassette and a different form to the 500-sheet tray. First let's gather our tools, then we'll build our solution.
Gathering Your Tools
First, you will need to extend AppleScript's capabilities by adding a file named "XCMD OSAX" to the "Scripting Additions" folder in your System Folder. This adds several new commands to AppleScript, including the one we'll use called "Choose Printer" written by Frédéric Rinaldi (see
http://www.scriptweb.com/osaxen/289.html for more information). It can be downloaded from:
ftp://mirror.apple.com/mirrors/gaea.scriptweb.com/applescript/osaxen/
xcmdosax.a14.sit.hqx
Once this file is in your "Scripting Additions" folder the "Choose Printer" command can be called by FileMaker Pro with the "Perform AppleScript" ScriptMaker command (command the command with a command?).
Next you need ResEdit 2.1.3, a utility used to alter the resources or the building blocks - of files and applications. You can download a copy from Apple's or Ziff Davis' web site at:
ftp://ftp.apple.com/Apple_Support_Area/Apple_Software_Updates/US/Macintosh/
Utilities/ResEdit_2.1.3.sea.bin
ftp://ftp.zdnet.com/pub/private/sWlIB/system_hardware_utilities/
apple_software/resed.hqx
[Note: Always use ResEdit on a COPY of the file or application you want to alter. NEVER use it on an original. You won't toast your Mac if you mess up a copy but you could do some weird things if you change the wrong thing in an original.]
Preparing Your Printers
Make two duplicates of the LaserWriter 8 printer driver in your Extensions folder. Drag them to the Desktop where we'll work on them. Name one duplicate "LabCassette250" and the other "LabCassette500".
Open ResEdit, select "Open" from the file menu, click "Desktop", and double click on the driver named "LabCassette250". A window opens displaying Icons and with cryptic names under them. On one of the bottom rows find the resource labeled "STR" and double click on it. In the list of ID numbers double click on the third or fourth item labeled "-8185". Now you may see what we're up to: this resource names the LaserWriter Prefs file. To prevent our solution from replacing the current LaserWriter Prefs, we want each driver to have its own preference file. So, in the String field type "LabCassette250 Prefs" (no quotes), leave the data field blank, then close the windows associated with this driver. Now open "LabCassette500" and do the same thing as you did above but enter "LabCassette500 Prefs" into the String field. When you finish, quit ResEdit and hide it someplace where careless hands won't find it! Lastly, drag both of these drivers to your Extensions folder.
Now we need to save the correct default paper trays for each driver. Open the Chooser and select "LabCassette250." Select the Lab Printer (your printer may have a different name) from the list to the right. If you see "Setup" below this list you should click it to tell the Mac to create a new
Desktop printer. (If you have multiple laser printers that use the LaserWriter 8 driver you can select them and save the 250-sheet cassette as
a default on them as well.) When this is done close the Chooser.
Now open any FileMaker Pro database, select "Print", choose "Cassette (250-sheets)" from the paper source pull-down menu (exact wording may vary depending on your printer), click the "Save Settings" button, click "OK" to accept, then cancel to get out of the print dialog box.
From the Chooser select the "LabCassette500" driver, select the Lab Printer, click "Setup" if available, and then close the Chooser. Now do the same thing as above but select "Cassette (500-sheet)" as the paper source before clicking "Save Settings." The same method could be used with the
multi-purpose tray and envelope feeder if installed on your printer.
The Scripts
Now we're ready to set FileMaker Pro up to take advantage of your handiwork.
In keeping with good Scriptological form (kudos to Mr. Petrowsky & John Mark Osborne) we'll make our scripts modular so they can be called easily from any other script or button. We want one script that chooses the Lab Printer with the 250-sheet cassette selected, one that chooses the 500-sheet cassette, and one that goes back to the original LaserWriter 8 driver with the user's default settings.
Open ScriptMaker and create the first script named "Choose Lab Cassette 250". Clear all the default steps and select the command "Perform AppleScript". Double click on the command and enter the following AppleScript text:
choose printer DriverName "LabCassette250" PrinterName "Lab Printer"
That's it! Now create a script named "Choose Lab Cassette 500" with the
AppleScript
choose printer DriverName "LabCassette500" PrinterName "Lab Printer"
Lastly, create a script named "Choose Original Printer" which will reset the Chooser to the original printer. We could write a simple script like those above that chooses the LaserWriter 8 driver. But what if the user had a different laser printer chosen so before we switched it for our printed report? The way I solved this problem was to create a global text field named "gCurrent Printer" which is set with the current printer name before a script calls either of the first two scripts above. I have a script named "Set Current Printer Name" that does nothing more than a Set Field to "gCurrent Printer" using the following calculation:
Left(
Status(CurrentPrinterName),
Position(Status(CurrentPrinterName), ",", 1, 1) - 1
)
The reason I use the Left() function is that Status(CurrentPrinterName)
gives the printer name as well as other information unnecessary for our purposes.
Now, here is the AppleScript to paste into your script "Choose Original
Printer". We are telling AppleScript to set a variable to the variable
"curpntr" to the value in the field "gCurrent Printer" and to use that value
to select the original printer in the LaserWriter 8 driver. Without these
steps the Lab Printer will be selected in the LaserWriter 8 driver since it
will be called from one of our scripts.
tell application "FileMaker Pro"
set curpntr to the cell "gCurrent Printer" in the database "name of your database"
end tell
choose printer DriverName "LaserWriter 8" PrinterName curpntr
Using This Solution
Now that your scripts have been defined you can call them from any script that needs to print to a specific paper tray. In our example above we wanted, with one button, to print a report to the 250-sheet cassette and a form to the 500-sheet cassette. Simply write a script that
1. Sets "gCurrent Printer" to the calculation above.
2. Generates your report and calls:
Perform Script [Sub-scripts, "Choose Lab Cassette 250"]
3. Goes the form you need and calls:
Perform Script [Sub-scripts, "Choose Lab Cassette 500"]
4. Returns to some layout,
5. Calls:
Perform Script [Sub-scripts, "Choose Original Printer"]
Remember to set the current printer name before calling any scripts.
Of course there are infinite ways to use this solution. The end result is such that the users enjoy a simple interface and are presented with no confusing or unnecessary decisions. They just see their forms and letters on top of the printer where they ought to be.
Thanks to John Mark Osborne for tipping me off to this possibility through part of a post to a newsgroup. It took a little digging to put the whole thing together but I hope it proves helpful for some of you on the Macintosh who design with your users in mind.
## END ##