hammerspoon2-docs
    Preparing search index...

    Namespace urlevent

    Handle URL events received by Hammerspoon 2. The module responds to hammerspoon2:// URLs and, when Hammerspoon 2 is configured as the system default handler, also to http://, https://, and mailto: URLs.

    URLs take the form hammerspoon2://eventName?key=value&key2=value2. The host component (eventName) selects the registered callback.

    hs.urlevent.bind("myEvent", (eventName, params, pid, url) => {
    console.log("param foo = " + params["foo"])
    })

    // Remove a binding
    hs.urlevent.bind("myEvent", null)

    Set hs.urlevent.httpCallback (or mailtoCallback) to a function. You must also set Hammerspoon 2 as the system default handler for the relevant scheme — see setDefaultHandler(_:_:).

    hs.urlevent.httpCallback = (scheme, host, params, fullURL, pid) => {
    // Forward to a real browser rather than swallowing the link
    hs.urlevent.openURLWithBundle(fullURL, "com.apple.safari")
    }
    const current = hs.urlevent.getDefaultHandler("https")
    console.log("Current HTTPS handler: " + current)

    const all = hs.urlevent.getAllHandlersForScheme("https")
    console.log("Available: " + all.join(", "))

    hs.urlevent.setDefaultHandler("https", "com.apple.safari")

    Variables

    httpCallback
    mailtoCallback

    Functions

    bind
    getAllHandlersForScheme
    getDefaultHandler
    openURL
    openURLWithBundle
    setDefaultHandler