mordaunt.dev/code

code / go-notify-darwin

go-notify-darwin

Rich notifications on macOS for Go

  • Go
  • Library
  • Notifications
  • macOS
  • Apple
  • Native
  • Bindings
  • cgo
  • Desktop
  • UserNotifications
clone
https://mordaunt.dev/code/go-notify-darwin
license
Unlicense OR MIT
activity
0 commitsthis year, since 2024

This package binds to Apple’s UNNotificationn framework in order to create rich notifications. A large part of the API is surfaced, however no guarantee is made about feature completeness or API stability.

Usage

Register your categories with notify.Init. Set your callback with notify.SetCallback. This will be called upon user interaction. Push notifications with notify.Notify.

Conveniences

In order to make this API convenient it allows you to specify actions within notifications directly. On the backend an ad-hoc UNNotificationCategory is created for that notification. The traditional method on macOS is to rather register all of your application’s notification categories at init time, which you can do via the notify.Init function.

Caveats

For notification interactions to work you must have an NSApp running. The example relies on Gio for this.

Example

To run the example:

cd ./example && go generate . && ./example.app/Contents/MacOS/noti

Commit log

Mirrored to sourcehut and GitHub.