Can UserNotifications be used in a command line program?

I have a cli program which does a thing for a while, and I'd like it to post a notification on the screen when it's done. Note that because it's a standalone program, not an app, it doesn't have a bundle, per se.

I tried to use UserNotifications, but I get an immediate error with the line

 let center = UNUserNotificationCenter.current()

With the error:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'bundleProxyForCurrentProcess is nil: mainBundle.bundleURL

My entire program to produce this bug:

import Foundation
import UserNotifications

let center = UNUserNotificationCenter.current()

print("Hello, World!")
Post not yet marked as solved Up vote post of hacksaw Down vote post of hacksaw
663 views

Replies

You may have better luck using CFUserNotificationDisplayNotice, an older and lower-level notification API.