I have two printers, a ColorLaserJet and a Monochrome, (black), LaserJet.
Most of my printing is done on the Monochrome LaserJet, I use the ColorLaserJet specifically for one of my apps, Call it AppColor.
My System’s Default, Chip Apple M1, Memory 8 GB, macOS Sonoma 14.2.1, is set to the Monochrome LaserJet.
When I want to print on the Monochrome LaserJet with my other apps I use g = openprinter and the dialog is bypassed because it goes directly to the default printer… the Monochrome LaserJet.
When I want to print on the ColorLaserJet with AppColor I have to use g = openprinterdialog and then select the ColorLaserJet.
How can I can code AppColor to bypass the default and print with the ColorLaserJet programatically?
If you have access to MBS plugins, then this will do what you’re looking for.
dim pi as new NSPrintInfoMBS
pi.printer = NSPrinterMBS.printerWithName("My Printer Name")
dim ps as new PrinterSetup
ps.SetupString = pi.SetupString
dim g As Graphics = OpenPrinter(ps)
I’m not sure how to build that setup string without the aid of the plugin though.
#if TargetMacOS or TargetLinux
myShell.Execute "lpoptions -d "+aPrinterName
#Elseif TargetWindows
myShell.Execute "wmic printer where name='"+aPrinterName+"' call setdefaultprinter"
#endif
you can get the actuel printer name with
#if TargetMacOS or TargetLinux
myShell.Execute "lpstat -d"
dim defaultPrinter as String = myShell.Result
myShell.Execute "lpstat -p"
' note : lpstat -d doit donner l'imprimante par défaut actuelle
#Elseif TargetWindows
myShell.Execute "wmic printer get name,default"
Dim result As String = myShell.Result
#endif
these were grabbed from this forum but I don’t have the actual posts anymore
Here is a project that demonstrates the concept. It prompts for the printer setup once and saves it to a file. It does that for the second printer as well. Then you can print to each printer without prompting the user again.