hammerspoon2-docs
    Preparing search index...

    Function on

    • Register a listener for screen events.

      "change" fires whenever the display configuration changes — monitors connected/disconnected, resolution or arrangement changes, or the menu bar moving to a different display. The listener gets no arguments; call all()/main()/primary() inside it to inspect the new configuration.

      "spaceChange" fires whenever a screen switches to a different space. If several screens switch at once, it fires once for each. The listener gets an object with the screen that switched (null if it has just been disconnected), the space it was showing before (from, null for a screen that has just been connected), and the space it's showing now (to).

      Parameters

      • event: "change" | "spaceChange"

        The event to listen for

      • listener: (
            change?: { from: HSSpace | null; screen: HSScreen | null; to: HSSpace },
        ) => void

        Called when the event happens; see above for its argument

      Returns void

      Throws an Error on failure; wrap calls in try/catch to handle it.