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 #
| Parameter | Type | Required | Values | What it does |
|---|---|---|---|---|
name | text | Yes | The event name. Required. | |
allowPageOrigins | list of text | Addresses (like https://example.com) whose own scripts may fire this event with postMessage. None by default. | ||
match | record | browser title url | Which 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 #
- A page on example.com/* sends the event “saved”
- Show “Saved {{data.id}}” for 2 s
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.runis a separate switch: see Callable from pages in the macro's settings.