This native Node.js module allows you to send and monitor Darwin-style notifications on macOS.
The Darwin-style notification API allow processes to exchange stateless notification events. Processes post notifications to a single system-wide notification server, which then distributes notifications to client processes that have registered to receive those notifications, including processes run by other users.
Notifications are associated with names in a namespace shared by all clients of the system. Clients may post notifications for names, and may monitor names for posted notifications. Clients may request notification delivery by a number of different methods.
Clients desiring to monitor names in the notification system must register with the system, providing a name and other information required for the desired notification delivery method. Clients that use signal-based notification should be aware that signals are not delivered to a process while it is running in a signal handler. This may affect the delivery of signals in close succession.
Notifications may be coalesced in some cases. Multiple events posted for a name in rapid succession may result in a single notification sent to clients registered for notification for that name.
const { getState, listener } = require('node-mac-notify')const name = 'my-event-name'const added = listener.add(name)console.log(`Event handler for ${name} was ${added ? 'successfully' : 'unsuccessfully'} added.`)const state = getState(name)console.log(`Current state of ${name} is ${state}`)