Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Yes, it is possible to use Swift to get the printing process on a Mac and receive a notification when it is finished. You can use the NSPrintOperation class to start a print job and the NSPrintOperationDidRunNotification notification to receive a notification when the print job is complete. Here's an example:

let printInfo = NSPrintInfo.shared
let printOp = NSPrintOperation(view: myView, printInfo: printInfo)

NotificationCenter.default.addObserver(forName: NSPrintOperationDidRunNotification,
                                       object: printOp,
                                       queue: nil) { notification in
    print("Printing finished!")
}

printOp.run()

In this example, myView is the view you want to print. Once you start the print operation with printOp.run(), you will receive a notification when it finishes.