Search code examples
macosswift3xcode8smbprinters

How can you add a remote printer to a Mac over smb? (Xcode 8, Swift 3)


We have a print-server with samba and I want to write a program for our users (for Mac) where they can see the printers they are allowed to use and add them to their system with just a mouse click.

What I've already got:

  • User can log in and see which printers they can/are allowed to connect to

  • User can remove printer from system

What I still want:

  • User can choose a printer from the list and add it with a mouse click



I already tried to add a Printer with 'NSPrinter' but when I want to initialize one with a name, it returns 'nil'.

I also tried to add a printer with
lpadmin -p NAME -v smb://ADDRESS -o printer-is-shared=false -E
but with this method my printer isn't added to printer-list in the 'systemconfiguration' an I also don't know how I could associate it with the right driver for Mac, like "Lexmark X544".



Ideas and criticism are welcome.
Thank you very much :)


Solution

  • This Blog-entry helped me understand that in Mac you do not really have a driver because all the "drivers" they show you in their selection when you add a printer over the menu are PPD's (PostScript Printer Description).


    Now that I understood that, I changed my command to:

    lpadmin -p NAME -v smb://ADDRESS -P /Path/to/PPD -o printer-is-shared=false -E

    and it also automatically created the Printer as NSPrinter for me.