Hello, Happy New Year,
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?
I’m using XOJO Version 2023 Release 4.
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.
I did this using external (local) files with setup’s for each printer I have to use, so I call each one per needs
I usually need to print on 2 printers different reports under the same method
This way I avoid asking to change setup each time I have to print
Thanks, but I am coding for personal, in-house, use, would prefer a solution without plugins.
you can do it with a call to a shell
#if TargetMacOS or TargetLinux
myShell.Execute "lpoptions -d "+aPrinterName
myShell.Execute "wmic printer where name='"+aPrinterName+"' call setdefaultprinter"
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
myShell.Execute "wmic printer get name,default"
Dim result As String = myShell.Result
these were grabbed from this forum but I don’t have the actual posts anymore
That’s a really interesting workaround.
Thanks, will have a go at it tomorrow.
Thanks Jean-Yves Pochez,
I found a post of yours,
Printing in a multi printer setup - best approach ?
I would appreciate if you can post a simple, bare-bones, project with that code.
the code I use is in that post you found …
really not mine.
Time ago I’ve been just looking to achieve this matter and found
I faced the problem this way:
// Saving the Printer Settings
Dim f As FolderItem
Dim strOut As TextOutputStream
Dim ps As New PrinterSetup
f = GetFolderItem("")
f = f.Child("PrinterSettings.txt")
' If the text file does not exist create it!
If f <> Nil Then
If ps.PageSetupDialog = True Then
Dim g As Graphics
g = OpenPrinterDialog(ps, Nil)
If g <> Nil Then
strOut = TextOutputStream.Create(f)
I had a bit of a problem with this because I have to work with printer servers of all kinds of versions.
with a p parameter by byref as printersetup
Dim f, fs As FolderItem
Dim bs As BinaryStream
Dim mb As MemoryBlock
fs = SpecialFolder.Documents.Child(App.kPrinterStringFile)
f = New FolderItem(fs)
If f <> Nil And f.Exists Then
// retrieve the setup string from the file if it exists
bs = BinaryStream.Open(f, False)
mb = DecodeBase64(bs.Read(bs.Length))
So this was my startpoint
By the way,Lennox I can drop you some code if you need. (althought I guess I would need to dust off my iMac
I would really appreciate it.
Thanks in advance.
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.
It’s old and was only tested on Windows.
Thnak you for your help. It will be my first example-ro-share so I really haven’t got idea about how to do.
I confirm this is the way I do (under windows)
I am using Mac though, I will see how I can modify it.
It compiles and runs for Mac without any issues.
My next step is to incorporate it into my apps.