Changing Printer in FMP7

I’ve just posted a solution to circumvent a bug of FileMaker Pro 7 at fmforums and I’m sure this could help other people wanting to change the printer by scripts even if they don’t use FMP7.

The bug is that in previous versions, FMP was recording the printer name within its Printer Setup step of his scripts. Since version 7 FMP prints to the last used printer whatever you do in your script.

I have found so many help reading this forum that I thought it was my turn to give something.So …

I dig a few in this problem and found a solution.
Before you go further to find a better
solution let me tell you my quest.

I have a solution with 2 printers, one for
lables one for invoices. As you could imagine,
I hope my FM scripts to change printer to
LabelWriter for the labels and to HP for
the invoices.

There’s some plug-ins but I was searching
for a free solution. I read some thread about
scripting the Printer Setup Utility, but this does
not work as far as FMP7 doesn’t care about
the default printer but only about the last used printer.

I tried to script the printer change using GUI
scripting of Panther (see http://www.apple.com/applescript/uiscripting/)
embeded in a DoApplescript step in a FMP Script. But that doesn’t work
because FMP Scripts are behaving a strange way :

  • if you put the Do Applescript step after the Print Step.
    FMP waits for an answer to the print dialog to launch the AppleScript.

  • if you put it before…The print step is not launch until
    the AppleScript is finished.

  • if you wrap the applescript in an “ignoring application
    responses/end ignoring” the scripts are so melting one
    with the other that FMP becomes mad

  • if you forget the Print Step in the FMP script but put it in
    the AppleScript, it doesn’t work because menus are not
    accessible while a script is running in FMP

So what…

Here is the only way I found :
1st make an applescript and save it as application
2 nd make your FMP script launch the AppleScript just a
step before the Print step

here is what my script looks like :
the “GotoLabelWriter 320” Applescript


tell application "System Events"
	tell application process "FileMaker"
		repeat until frontmost   --this repeat to be sure FMP is the frontmost app
			set frontmost to true
		end repeat
		repeat until exists window "Imprimer   --this one to wait until the printing dialog appears
		end repeat
		repeat until value of pop up button 3 of window "Imprimer" is "LabelWriter 320" --and finaly this one to change the printer
			click pop up button 3 of window "Imprimer"
			click menu item "LabelWriter 320" of menu "Popup:" of pop up button 3 of window "Imprimer"
		end repeat
	end tell
end tell

here is the FMP Script :

Step Do AppleScript =

tell application "Finder"
ignoring application responses
open file "GotoLabelWriter 320" of folder "Documents" of  home
end ignoring
end tell

followed by the Print step

Hope this helps.

Don’t forget to Enable access for assistive devices of the Universal Access
pane of the System Preferences si that GUI Scripting works in Panther.

waiting for comments

Regards

Vartan

Hi - this sounds perfect! Same situation here: trying to switch between a regular network printer and Dymo LabelWriter 330, which is a USB.

Will this work for FM6, on OS9? If not, which step do I need to change?

Thanks so much.

Sorry but this won’t work on OS 9, for thos to work you have to be at least in OS X.3 I think, perhaps in 10.2.8 (to be verified). This is beacause os the GUI Scripting wich is not working on OS 9.

There’s a third party OSAX on OS 9 doing some GUI Scripting but it is not as efficient as the on on OS X, but you can try to adapt these scripts

I used your solution to switching printers via Applescripting in the scirptmaker of FMP7. I know “very” little about Applescripting but was able to follow your directions. Is there a way to automate the actual “pint” button so I don’t have stop and hit the “print” button? If I try using the FMP7 script choice of printing without the dialog box, it interferes with the completion of the Applescript. Can you help?

This is an awful way to get it done. Try this:

I recently needed to switch printers using scripting in Filemaker Pro 7. Filemaker officially supports the feature but it is buggy and will often not work (the bug is documented by Filemaker). So before printing using a FM script I wanted to change the defaultprinter. And Applescript only supports that using UI scripting. I figured Cups/GIMP would have the feature as well in a terminal command.

The commands I used to figure this all out are documented on the Cups/GIMP webpages. (You can even check ink reserves in inkjet printers using terminal!). How to do it all:

All quotes and brackets should be ignored except in the Applescript. In the terminal you can do:

“lpstat” gives you status of printerqueue’s and the names.
“lpoptions” allows printer settings to be changed for the current user.
“lpadmin” allows the settings to be changed for all users but I couldn’t get that to work (user settings override I guess).

Do “lpstat -a” in the terminal, it returns:

ruben-van-der-laans-powerbook-g4-17:~ rlaan$ lpstat -a
HP_LaserJet_4100_MFP__0001E66197AF_ accepting requests since Jan 01 00:00
HP_LaserJet_4100_Series__000E7FDE2702_ accepting requests since Jan 01 00:00

Two Laserjets, the printername is actually the queue name. To change the default printer to the MFP machine do:

“lpoptions -d HP_LaserJet_4100_MFP__0001E66197AF_”

without quotes.

Filemaker can do an Applescript:

do shell script (“lpoptions -d HP_LaserJet_4100_MFP__0001E66197AF_”)

I used the quotes in that in Filemaker, and I put the script right at the beginning of the Filemaker script. And it works like a charm! Fast clean and mean. And no UI scripting. This is invisible.

Hi:

This is interesting, however…

I can use the lpstat -a to get the names of my printers, but they have parentheses in their names, for example:

hp_LaserJet_4300_(0001E68B4E89)

We have several of these 4300 printers. When I try the shell script I get errors like “syntax error near unexpected token '(…”. I tried various escaping maneuvers, but no luck. I can successfully specify “AdobePDF” or any other printer without parentheses in its name.

Do you know how to formulate the lpoptions -d to accept a printer with parentheses in its name?

The commands I used to figure this all out are documented on the Cups/GIMP webpages

What is the URL?

Thanks,

guy o

Just change the ( and the ) mark in an underscore and it should work.
in your case hp_LaserJet_4300_(0001E68B4E89) would become: hp_LaserJet_4300__0001E68B4E89_
note that after the 4300 you 'll find two underscores

Check: http://127.0.0.1:631 for Cups info and url’s with extra info.

Cheers

Ruben

Well, known of these solutions fix FMP if its restoring printing settings from within a script. The applescript comes the closes though with the following changes (and using the word Pint" insted of "Imprimer and using my choice of 4-Sight Fax server). Has anyone figured out how to make this worke with FMP7? There occurs as marked below.

tell application “System Events”
tell application process “FileMaker”
repeat until frontmost --this repeat to be sure FMP is the frontmost app
set frontmost to true
end repeat
repeat until exists window “Print” --this one to wait until the printing dialog appears
end repeat
repeat until value of pop up button 3 of window “Print” is “4-Sight Fax” --and finaly this one to change the printer
click pop up button 3 of window “Print”
tell menu “Popup:” of window “Print”
click menu item “4-Sight Fax” of pop up button 3 of window “4-Sight Fax” ==this thross a NSReceiver 5 errore.
end tell
end repeat
end tell
end tell:/