pub-NSDNC

The pub-<MsgEnv> for macOS. The ME is NSDistributedNotificationCenter, the publish/subscribe that macOS already provides between the processes of a user session.

Repository

https://gitlab.com/industry-of-integrations/pub-NSDNC

Wrapper library

https://github.com/IPSME/objc-msgenv-NSDNC

USAGE: pub-NSDNC <0|1> <string>

What it does

  1. Generates a UUID for this run.

  2. Subscribes to the ME.

  3. Publishes <string>, with the UUID as the notification’s object.

  4. Runs the run loop in slices of one second. With 1 it loops until stopped with ^C; with 0 it runs one slice and exits.

Every message heard is logged through NSLog as pub ← nsdnc — […​]. The tool’s own message comes back too; it is recognised by the UUID in the notification’s object and dropped without a line. This is the "referer" clause from the IPSME conventions in its simplest form.

On the wire

Notification name

IPSME

Payload

userInfo dictionary, key msg

Object

the publisher’s UUID string

All participants on this ME share the one notification name; IPSME does not divide an ME into channels. The payload travels in userInfo because macOS no longer accepts nil as a name filter when observing.

Apple forbids sandboxed apps from sending userInfo in distributed notifications. pub-NSDNC is not sandboxed. A participant that is sandboxed cannot publish on this ME and needs another one, such as a WebSocket or MQTT over the network.

Source and build

The repository is an Xcode project; the tool is pub-NSDNC/main.m. The wrapper library objc-msgenv-NSDNC comes in as a git submodule and provides IPSME_MsgEnv (subscribe:, publish:withObject:).

make xcode   # xcodebuild, Release, arm64, into _DerivedData
make dist    # bin/pub-NSDNC, Info.plist, dist/pub-NSDNC@<version>.tar.gz and its .sha384

The version comes from CFBundleShortVersionString in pub-NSDNC/Info.plist; package.json carries the same number.

make dist is what feeds the npm package @ioi-ri/pub-nsdnc, for darwin only. Info.plist declares it an IOI_CommandLineBinary, so it is a command and not an agent: nothing is loaded into launchd.