Browse the docs

A page sends an event

Runs the macro when injected page code calls switchboard.emit, or a button in injected HTML with data-switchboard-emit is clicked.

A page sends the event name

Details #

Pages talk to Switchboard through the switchboard object that Put CSS, HTML or JavaScript in the page puts in the page:

switchboard.emit("saved", { id: 42 })

or with no code at all: <button data-switchboard-emit="saved">Save</button> in injected HTML.

The run starts with the page's inputs plus name and data. {{triggerValue}} is the data.

Ordinary page code (a site's own scripts) can only fire the event with window.postMessage({ switchboard: { emit: "saved", data } }, "*"), and only from an address listed in allowPageOrigins. By default none are.

Parameters #

ParameterTypeRequiredValuesWhat it does
nametextYesThe event name. Required.
allowPageOriginslist of textAddresses (like https://example.com) whose own scripts may fire this event with postMessage. None by default.
matchrecordbrowser title urlWhich pages. url is a pattern (https://*.github.com/*/pull/*), a plain start (github.com/apple) or /regex/; title is text (any case) or /regex/; browser is safari, chrome or any.

Every trigger also takes Limits: a cooldown, the first time each day, every nth time, twice within seconds, a chance, only while you are at the Mac, on one Mac, or in a State. See Limits on any trigger.

Examples #

Run when injected code says the job is done
When
  1. A page on example.com/* sends the event “saved”
Do
  1. Show “Saved {{data.id}}” for 2 s
Open in Switchboard to try it

Gotchas #

  • Page code can't run macros this way, only start the ones that wait for an event by name.

  • A macro called with switchboard.run is a separate switch: see Callable from pages in the macro's settings.