Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Choose printer with Applescript?

Featured Replies

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?

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.

  • Author

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

  • Author

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!!

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

  • Author

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)?

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.

  • Author

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?

Yes, it does!!!

(Your enthusiasm is great - happy programming.)

  • Author

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?

Works for me. Be careful about the linebreaks. Sometimes linebreaks are added when copying out of your browser.

  • 2 weeks later...
  • Author

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.

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.

  • Author

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...

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...

I have run into interesting bugs with FMD 6. Have you done the process of elemination? Like telling Print Center to set a variable?

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.