Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 7761 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

I would like to print from a different printer for some scripts.

Can OS X's print dialog be scripted in this way? or do I have to use the Change Printer plugin?

Posted

I believe its possible, through the 'Print Center' application. Take a look at the dictionary for it in script editor, it has some pretty good power to it.

Posted

Wow I am SOOOO excited that I probably won't need a plugin for this! OS 9 was such a pain cause the chooser was not scriptable (desktop printers only)...

Here is a script I found on macosxhints.com:

tell application "Print Center"

set printerlist to name of printers

set oldprinter to name of current printer

set printerchoice to (choose from list printerlist with prompt

Posted

Woops... I just realized that although I only have one printer, I have two printers in my printer list, so I managed to figure out that I need the following for it to work:

tell application "Print Center"

set printerchoice to "Stylus COLOR 880"

set current printer to printer (printerchoice as string)

end tell

I don't really understand why this works and the other didn't, but hey, it works! Yahoo!!

Posted

You can simplify your script to just one line...

tell application "Print Center" to set current printer to printer "Stylus COLOR 880"

I recommend adding error capture so that your users don't get cryptic error messages

try

tell application "Print Center" to set current printer to printer "Stylus COLOR 880"

on error

display dialog "Could not set printer preferences. Please contact your system administrator" buttons {"OK"} default button 1

end try

Posted

I recommend adding error capture so that your users don't get cryptic error messages

Excellent! That was going to be my next question.

Now is there any way to pass a field value in FM for the printer name *without* having to make the whole script a calculation field (and thus requiring it to complile each time--which I assume slows it down)?

Posted

Sure. Just start the script with a line...

tell app "FileMaker Pro" to set thePrinterString to cell "PrinterPrefs" of current record

and then just substitute thePrinterString for the "Stylus COLOR 880" in the script above. You will likely want to make your field ("PrinterPrefs" or whatever) a global field.

Posted

WOW that's amazing!!!! Pardon my enthusiasm... I am soooo thrilled I can do all this with AppleScript!

Does "tell app" simply replace the "tell" and "end tell" for simple one line instructions?

Posted

try

tell application "Print Center" to set current printer to printer "Stylus COLOR 880"

on error

display dialog "Could not set printer preferences. Please contact your system administrator" buttons {"OK"} default button 1

end try

This didn't work for me..

Error: expected "end" or "end tell" but found "on"

... so I assumed it's supposed to be "onerror"

Then I get this error:

Expected "tell" but found "try" (right at the very end)

... if I change it to "end tell" it says "Expected end of line but found end of script".

What did I miss?

  • 2 weeks later...
Posted

I just got my demo receipt printer and cash drawer so I finally got a chance to test all of this out. It works wonderfully.

I have noticed one limitation in OS X Print Center it seems. When I switch to the receipt printer, then print a receipt, then immediately switch back to a laser printer... you have to wait several seconds (10 maybe?) before you can print again on the laser as a default, even though you can clearly see in the print center that the default was changed back instantly. This seems odd because it changes so fast the first time (and it works), it's only when changing back that you have to wait!

This is only a problem for me because I tried to do a script for full page invoices that would first send a blank job to the receipt printer (to open the cash drawer), then send the invoice to the laser printer... The receipt printer ends up printing the laser print job (wow--worlds smallest invoice!). The same thing happens if I reverse the order (in this case, both jobs get sent to the laser printer).

This is probably something Apple will resolve... word is the Print Center has a lot of development planned.

Posted

When I originally posted my method for switching printers in OS9, I found that I had to monitor the print queue and wait until it was empty before switching printers. Otherwise, the print job could end up not printing until the next time the printer was selected. Could be something similar here. The delay may be related to the time it takes to finish the print job in the queue.

Posted

That is exactly what I suspected. I proved it not *completely* right by sending a slightly bigger job (to give me more time), and noticed that it would still switch after a few seconds even if the job is still going...

But I do believe you are correct that they are related.

There's probably a step in there somewhere that makes the difference (eg: from "connecting" to "processing" for example.

  • 6 months later...
Posted

can anyone tell me why I get the error message "Error -2709. Can't find application's event dictionary" when trying to AppleScript the Print Center in FMD ? When I run a straight AppleScript (outside of FM), there is no problem.

  • 3 weeks later...

This topic is 7761 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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