Ask Your Question
3

Is it possible to use Swift to get the printing process on a Mac and receive a notification when it is finished?

asked 2023-06-06 09:29:37 +0000

lalupa gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-06-06 09:55:02 +0000

djk gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-06 09:29:37 +0000

Seen: 9 times

Last updated: Jun 06 '23