Jump to content
Sign in to follow this  
BobWeaver

Selecting Printer Paper tray with Scriptmaker

Recommended Posts

A question that comes up regularly is:

How can I select the printer's paper tray from a Filemaker script?

The solution that I have found on Macintosh platforms is to use modified PPD files for the printer. The PPD file is modified so that it overrides the default tray selection that is normally chosen in the print dialog. So, you would create a special PPD file for tray 1, a special PPD file for tray 2, and a special PPD file for the manual feed slot. Then, using applescript, you set the appropriate PPD file for the pages that you will print.

First, some information on PPD files.

You can think of a PPD file as an instruction manual that is used by the generic postscript printer driver to figure out how to use the special features of your specific printer. For example, if the user selects the manual feed option in the print dialog, the printer driver needs to figure out how to tell your "Brand X" printer to do that. It goes into the PPD file and looks up the section dealing with paper source and selects the appropriate snippet of PS code which it then inserts into the printer spool file.

So, if we want to ensure that the printer alway prints from the manual feed slot, all we have to do is substitue the manual feed PS code for all of the paper source options. It's simply a matter of changing a single line of code in the file.

Following is an example for making a PPD file that will always force your printer to use the manual feed slot. Further down is information on making a PPD file to use a specific tray.

A Manual Feed Only PPD file

1. Make a duplicate of your printer's PPD file. You will find it in the folder, System Folder:Extensions:Printer Descriptions.

For Example, the PPD file for my Dataproducts LZR 960 is called "LZR 960." Rename the duplicate "LZR 960MF," so you don't forget that this is a modified file.

2. Open the duplicate PPD file with a text editor and search for the section of code that begins with "*OpenUI *ManualFeed...."

If it's a Postscript level 1 printer, the code will likely look something like this:

code:

*OpenUI *ManualFeed/Manual Feed: Boolean

*OrderDependency: 20 AnySetup *ManualFeed

*DefaultManualFeed: False

*ManualFeed True: "1 dict dup /ManualFeed true put setpagedevice"

*ManualFeed False: "1 dict dup /ManualFeed False put setpagedevice"

etc.


Change the last line to:

*ManualFeed False: "1 dict dup /ManualFeed True put setpagedevice"

If it's a Postscript level 2 printer, the code will look like this:

code:

*OpenUI *ManualFeed/Manual Feed: Boolean

*OrderDependency: 20 AnySetup *ManualFeed

*DefaultManualFeed: True

*ManualFeed True: "<</ManualFeed true>> setpagedevice"

*ManualFeed False: "<</ManualFeed false>> setpagedevice"

etc.


Change the last line to:

*ManualFeed False: "<</ManualFeed true>> setpagedevice"

3. Save the file.

4. To change to manual feed, execute the following Applescript from your Filemaker script:

code:

set PPDPath to "Macintosh HD:System Folder:Extensions:Printer Descriptions:"

-- Set name of modified manual feed PPD file

set PPDName to "LZR 960MF"

tell application "Desktop Printer Manager"

set the PPD_file to (PPDPath & PPDName) as string as alias

--My printer is named "Fluffy." Use your own printer name in the following line

set the PPD file of desktop printer "Fluffy" to PPD_file

end tell


To switch back to normal, execute the following:

code:

set PPDPath to "Macintosh HD:System Folder:Extensions:Printer Descriptions:"

--Set name of normal PPD file

set PPDName to "LZR 960"

tell application "Desktop Printer Manager"

set the PPD_file to (PPDPath & PPDName) as string as alias

set the PPD file of desktop printer "Fluffy" to PPD_file

end tell


If your Filemaker script displays the print dialog before it prints, you won't see any difference in the paper source selection, but it will use the manual feed slot no matter which paper source the user selects.

So, be sure to change back to the original PPD file after you are finished manual feed printing, or there will be a lot of confusion in the office.

A PPD file to Force a Specific Paper Tray

Following is typical code from a PPD file that selects the paper tray. The important thing to note here is that the code for tray 1, tray 2 and envelope feeder is identical except for the constants 0, 1, and 2 which appear at the beginning of the line following "currentpagedevice /InputAttributes get."

code:

*OpenUI *InputSlot: PickOne

*OrderDependency: 20 AnySetup *InputSlot

*DefaultInputSlot: Top

*InputSlot Top/Tray 1/Upper: "

currentpagedevice /InputAttributes get

0 get dup

null eq {pop}

{ dup

/InputAttributes

1 dict dup /Priority [0] put

put setpagedevice

} ifelse "

*End

*InputSlot Tray2/Tray 2: "

currentpagedevice /InputAttributes get

1 get dup

null eq {pop}

{ dup

/InputAttributes

1 dict dup /Priority [1] put

put setpagedevice

} ifelse "

*End

*InputSlot Envelope/Envelope Feeder: "

currentpagedevice /InputAttributes get

2 get dup

null eq {pop}

{ dup

/InputAttributes

1 dict dup /Priority [2] put

put setpagedevice

} ifelse "

*End

*?InputSlot: "

save

3 dict

dup /0 (Top) put

dup /1 (Tray2) put

dup /2 (Envelope) put

currentpagedevice /InputAttributes get

dup /Priority known

{ /Priority get 0 get ( ) cvs cvn get }

{

dup length 1 eq

{ {pop} forall ( ) cvs cvn get }

{ pop pop (Unknown) } ifelse

} ifelse

= flush

restore

"

*End

*CloseUI: *InputSlot


We can infer that 0=Tray 1, 1=Tray 2, and 2=Envelope Feeder. So, if we want to force the printer to always print from tray 2, we just change the constant to 1 in each of these sections of code. Then, no matter which chunk of code the print driver uses, it will be telling the printer to use tray 2. Once the modified file is saved, it can be selected as necessary using the same applescript code given previously.

I expect that this will also work on Windows platforms as long as you are able to select the PPD file under script control. Winbatch may be able to provide this function, although I have no experience with it.

[ December 18, 2001: Message edited by: BobWeaver ]

Share this post


Link to post
Share on other sites

Jeff Cooper came up with a much more elegant solution here. So, this method can be relegated to the scrap heap smile.gif

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.