jasonwood Posted January 3, 2003 Posted January 3, 2003 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?
keshalyi Posted January 3, 2003 Posted January 3, 2003 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.
BobWeaver Posted January 5, 2003 Posted January 5, 2003 You can check out this post: http://www.fmforums.com/threads/showflat.php?Cat=&Board=UBB8&Number=1458&page=1&view=collapsed&sb=5&o=all&fpart=1 I wrote it a while back, and it's intended for OS9, but should be adaptable to OSX.
jasonwood Posted January 5, 2003 Author Posted January 5, 2003 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
jasonwood Posted January 5, 2003 Author Posted January 5, 2003 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!!
jfmcel Posted January 6, 2003 Posted January 6, 2003 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
jasonwood Posted January 6, 2003 Author Posted January 6, 2003 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)?
jfmcel Posted January 7, 2003 Posted January 7, 2003 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.
jasonwood Posted January 7, 2003 Author Posted January 7, 2003 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?
jfmcel Posted January 7, 2003 Posted January 7, 2003 Yes, it does!!! (Your enthusiasm is great - happy programming.)
jasonwood Posted January 7, 2003 Author Posted January 7, 2003 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?
jfmcel Posted January 7, 2003 Posted January 7, 2003 Works for me. Be careful about the linebreaks. Sometimes linebreaks are added when copying out of your browser.
jasonwood Posted January 18, 2003 Author Posted January 18, 2003 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.
BobWeaver Posted January 19, 2003 Posted January 19, 2003 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.
jasonwood Posted January 19, 2003 Author Posted January 19, 2003 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.
ChrisE Posted August 6, 2003 Posted August 6, 2003 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.
Chris Williams Posted August 26, 2003 Posted August 26, 2003 I have run into interesting bugs with FMD 6. Have you done the process of elemination? Like telling Print Center to set a variable?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now