Skip to content

The client

When you are looking to integrate macos-notifications with your project, the client is the first place to look. If you have a service that periodically restarts, you might want to take a look at the CacheClient.

client

create_notification(title='Notification', subtitle=None, text=None, icon=None, delay=timedelta(), action_button_str=None, action_callback=None, reply_button_str=None, reply_callback=None, snooze_button_str=None)

Create a MacOS notification :)

Parameters:

Name Type Description Default
title str

Title of the notification.

'Notification'
subtitle str | None

The subtitle of the notification.

None
text str | None

The text/main body of the notification.

None
icon str | Path | None

An Icon you would like to set on the right bottom.

None
delay timedelta

Delay before showing the message.

timedelta()
action_button_str str | None

The string of the Action button.

None
action_callback Callable[[], None] | None

The function to call when the action button is pressed.

None
reply_button_str str | None

The string of the Reply button.

None
reply_callback Callable[[str], None] | None

The function to call with the replied text.

None
snooze_button_str str | None

This is a useless button that closes the notification (but not the process). Think of this as a snooze button.

None
Source code in mac_notifications/client.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def create_notification(
    title: str = "Notification",
    subtitle: str | None = None,
    text: str | None = None,
    icon: str | Path | None = None,
    delay: timedelta = timedelta(),
    action_button_str: str | None = None,
    action_callback: Callable[[], None] | None = None,
    reply_button_str: str | None = None,
    reply_callback: Callable[[str], None] | None = None,
    snooze_button_str: str | None = None,
) -> Notification :
    """
    Create a MacOS notification :)
    :param title: Title of the notification.
    :param subtitle: The subtitle of the notification.
    :param text: The text/main body of the notification.
    :param icon: An Icon you would like to set on the right bottom.
    :param delay: Delay before showing the message.
    :param action_button_str: The string of the Action button.
    :param action_callback: The function to call when the action button is pressed.
    :param reply_button_str: The string of the Reply button.
    :param reply_callback: The function to call with the replied text.
    :param snooze_button_str: This is a useless button that closes the notification (but not the process). Think of
    this as a snooze button.
    """
    notification_config = NotificationConfig(
        title=title,
        subtitle=subtitle,
        text=text,
        icon=(str(icon.resolve()) if isinstance(icon, Path) else icon) if icon else None,
        delay=delay,
        action_button_str=action_button_str,
        action_callback=action_callback,
        reply_button_str=reply_button_str,
        reply_callback=reply_callback,
        snooze_button_str=snooze_button_str,
    )
    return get_notification_manager().create_notification(notification_config)

get_notification_manager()

Return the NotificationManager object.

Source code in mac_notifications/client.py
19
20
21
def get_notification_manager() -> NotificationManager:
    """Return the NotificationManager object."""
    return NotificationManager()

More advanced usages

To get a bit more information about the amount of notifications that are still active, you can use the following function:

get_notification_manager()

Return the NotificationManager object.

Source code in mac_notifications/client.py
19
20
21
def get_notification_manager() -> NotificationManager:
    """Return the NotificationManager object."""
    return NotificationManager()