Browse the docs

Before a key, click or quit

Catches a key press, a click on a button you recorded, or Quit in one app before the app sees it, runs a quick check macro, then lets it through, blocks it with a reason, or asks "Send anyway?".

Before a key or click in app

Details #

Every other trigger starts a macro after something happens. This one starts it before: the key, click or Quit is held back for a moment, the macro checks what it needs to, and the macro's answer decides what the app gets.

The answer is the macro's returned value, and the three steps Let it through, Block it and Ask Send anyway? return it for you:

The macro ends withWhat happens
hook.allow, or ends without returning anythingThe key, click or Quit goes through as if nothing was in the way.
hook.blockIt is dropped, and the reason shows for two seconds.
hook.askA small panel opens at the pointer with your question and two buttons. Return and Esc pick the cancel button; Command-Return picks the other.

Keys typed while the check runs are held and go to the app afterwards, in the order you typed them. Nothing is lost, and a check that finishes in a few milliseconds is not noticeable.

The macro gets these inputs:

InputWhat it holds
appThe bundle identifier of the app.
onkeys, click or quit.
keysThe key combination, for keys and quit.
elementFor click: {role, title, value} of what was clicked.

Parameters #

ParameterTypeRequiredValuesWhat it does
apptextYesRequired. The bundle identifier of the app to guard, such as com.apple.mail, or * for every app (keys and Quit only). A guardrail only ever looks at its own app.
deadlinenumberHow many seconds the check may take. Default 2, at most 10.
keystextFor keys: the combination, such as cmd+return. quit always means Command-Q.
locatorlocatorFor click: the button, recorded with the Recorder like any other element.
onone ofkeys click quitkeys (the default), click or quit.
onTimeoutone ofallow blockWhat happens when the check is too slow or fails: allow (the default) or block.

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 #

Ask before sending a message that mentions an attachment but has none
When
  1. Before ⌘↩ reaches Mail
Do
  1. Read the mail being written
  2. If body matches “(?i)attach(ed|ment)” and {{ attachmentCount }} is 0
  3. Ask “No attachment. The message mentions one.” with “Send Anyway”
Open in Switchboard to try it

Gotchas #

  • If the check is slow or fails, the action goes through (or is blocked, if you set onTimeout to block). The run's trace says which.

  • Secure input turns guardrails off, such as while a password field has focus. The menu bar item says so.

  • Only the key equivalent is guarded. Choosing the same command from a menu, the Dock's Quit, Force Quit and logging out can't be caught.

  • A hot key macro that claims the same key runs instead, and the guardrail never sees it.

  • If you switch to another app while a check runs, the held action is dropped rather than sent to the wrong app.

  • A click is looked at only in an app that has a click guardrail, and Accessibility has 80 milliseconds to answer. An app that does not answer is not guarded for that click.

  • Settings > Guardrails shows each guardrail's delay. A slow one is marked with an amber dot.

See also #

Let it through (guardrail), Block it (guardrail), Ask Send anyway? (guardrail), Read the mail being written, Hotkey, Guardrails: check before it happens