desktop_notifier.macos

UNUserNotificationCenter backend for macOS.

  • Introduced in macOS 10.14.

  • Cross-platform with iOS and iPadOS.

  • Only available from signed app bundles if called from the main executable or from a signed Python framework (for example from python.org).

  • Requires a running CFRunLoop to invoke callbacks.

Module Contents

Classes

CocoaNotificationCenter

UNUserNotificationCenter backend for macOS

class desktop_notifier.macos.CocoaNotificationCenter(app_name='Python', notification_limit=None)[source]

Bases: desktop_notifier.base.DesktopNotifierBase

UNUserNotificationCenter backend for macOS

Can be used with macOS Catalina and newer. Both app name and bundle identifier will be ignored. The notification center automatically uses the values provided by the app bundle.

Parameters:
  • app_name (str) – The name of the app. Does not have any effect because the app name is automatically determined from the bundle or framework.

  • notification_limit (Optional[int]) – Maximum number of notifications to keep in the system’s notification center.

_to_native_urgency[source]
async request_authorisation()[source]

Request authorisation to send user notifications. If this is called for the first time for an app, the call will only return once the user has granted or denied the request. Otherwise, the call will just return the current authorisation status without prompting the user.

Returns:

Whether authorisation has been granted.

Return type:

bool

async has_authorisation()[source]

Whether we have authorisation to send notifications.

Return type:

bool

async _send(notification, notification_to_replace)[source]

Uses UNUserNotificationCenter to schedule a notification.

Parameters:
Return type:

str

async _create_category_for_notification(notification)[source]

Registers a new notification category with UNNotificationCenter for the given notification or retrieves an existing one if it exists for our set of buttons.

Parameters:

notification (desktop_notifier.base.Notification) – Notification instance.

Returns:

The identifier of the existing or created notification category.

Return type:

Optional[str]

async _get_notification_categories()[source]

Returns the registered notification categories for this app / Python.

Return type:

NSSet

_clear_notification_categories()[source]

Clears all registered notification categories for this application.

Return type:

None

async _clear(notification)[source]

Removes a notifications from the notification center

Parameters:

notification (desktop_notifier.base.Notification) – Notification to clear.

Return type:

None

async _clear_all()[source]

Clears all notifications from notification center. This method does not affect any notification requests that are scheduled, but have not yet been delivered.

Return type:

None