hammerspoon2-docs
    Preparing search index...

    Namespace ipc

    Module for enabling CLI access to Hammerspoon 2 via the hs2 command-line tool. IPC must be explicitly started from your configuration — it does not run by default. Once started, the hs2 command-line tool can evaluate JavaScript interactively, with optional live log streaming. hs2 and Hammerspoon 2 talk to each other via XPC, through a small broker process (HammerspoonIPCBroker) that ships inside the app bundle. The first call to start() registers the broker with launchd as a background item, which macOS will tell you about in a notification. If the broker is disabled in System Settings → General → Login Items & Extensions, IPC will not work until it is re-enabled. launchd starts the broker on demand, and it exits by itself when nothing has been connected for a while. Communication is secured with a same-team code-signing requirement in release builds, so only binaries signed with the same Team ID can connect.

    // In your Hammerspoon 2 config (init.js):
    hs.ipc.start()
    hs.ipc.installBinary()   // symlinks hs2 to /usr/local/bin/hs2
    
    hs2
    hs2> hs.reload()
    undefined
    hs2> 2 + 2
    4
    hs2 --log-level info
    

    JavaScript can also be piped or redirected into hs2, one statement per line. When it isn't running interactively, hs2 exits with status 65 if any of the lines threw an

    echo 'hs.reload()' | hs2 --no-prompt || echo "failed with status $?"
    hs2 --no-prompt < script.js

    Variables

    isListening

    Functions

    installBinary
    isBinaryInstalled
    start
    stop
    uninstallBinary