Skip to main content

Before and after actions

note

Advanced mode. The Before and after tab on the App groups page, and the Before and after timeout on the Scripts page, are shown in Advanced mode only. Before and after scripts you set up keep running in Simple mode.

A Before script runs ahead of every action an app group runs, and an After script runs once the action has finished. Use them for work every action in a group shares: bringing a window to the front first, saving the clipboard and restoring it afterwards, logging.

They wrap every match in the group: gestures, hotkeys and text expansion alike. They don't wrap global events.

Setting them up​

Input.ObserverSimpleAdvanced
AUTOMATION
Actions
Text expansion
Snippets
Recorder
Sandbox
App groups
Ignore groups
Gestures
ENGINE
Global events
Exclusion zones
Scripts
Plugins
SETUP
General
Appearance
Profiles
Console
Security
Help
About
App groups
Browsers
GlobalRESERVED
App groups
Before and after
A script that wraps every action in this group: the Before one runs first, the After one last.
Before every action
Inherit from GlobalCustomNone
Written as
StepsScriptAutoHotkey
After every action
Inherit from GlobalCustomNone
  1. On App groups, select the group and find the Before and after card.
  2. Under Before every action ①, choose Custom.
  3. Under Written as ②, choose how to write the script: as Steps, as a Script, or (when AutoHotkey is turned on) as AutoHotkey. Then write it, as you would an action. See Steps and the script language.
  4. Do the same under After every action ③, or leave it on Inherit from Global.
  5. Apply your changes.

Each of the two has its own choice:

ChoiceWhat runs
Inherit from Global (the default)The Global group's Before (or After) script, if it has one. If it hasn't, nothing.
CustomThis group's own script. A Custom script with nothing in it runs nothing, like None.
NoneNothing, even if the Global group has a script.

The Global group's scripts are set in the same card on the Global group, which offers only Custom and None: there is nothing above Global to inherit from. They are what every Inherit from Global group runs, and what runs around Global's own actions.

Which group's scripts run​

The scripts of the group whose action ran are used, not those of the window's group:

The action that ran came fromBefore and After used
The window's own app groupThat group's choice: its own, Global's (Inherit), or none
The Global group, because the window has no groupGlobal's
The Global group, by falling back from the window's groupGlobal's, never the window's group's

The order of everything​

When a gesture matches, these run strictly one after another:

  1. Activate the window under the gesture, if that setting is on (gestures only). See Drawing a gesture.
  2. Held modifier keys are released, if the trigger's Held modifier keys is Release, then restore. See Modifiers and timing.
  3. Before, until it finishes or the timeout ends it.
  4. The action, for as long as it takes.
  5. After, until it finishes or the timeout ends it.
  6. Held modifier keys are pressed again, if step 2 released them.

Details:

  • Before can't cancel the action. The action runs once Before ends, even when Before failed with an error or was stopped by the timeout.
  • The action is never cut short by the timeout. After starts only when the action has finished.
  • The stop-all-actions hotkey stops whichever part is running and skips the rest, After included.
  • The same trigger information. Before and After see the same gesture, window and trigger details as the action (the Context builtins in the script reference).
  • Each match runs its own sequence. Two gestures drawn in quick succession run their sequences at the same time, each in its own order.
  • The Draw button released global event is not part of the sequence: it starts when you let go, alongside it.
  • Text expansion: the typed text is erased before Before runs, and the key that ended it (a space, for example) is typed after the action, before After runs. See Text expansion.

When a group resolves to no Before and no After script, the action runs on its own.

Before and after timeout​

Before and after timeout on the Scripts page, Limits and timeouts card, limits how long each Before or After script may run: 3,000 milliseconds by default, from 0 to 60,000. A script still running after that is stopped and the next step starts, with no message box; the diagnostic console shows a line about it (see The diagnostic console). At 0, each one gets about 20 milliseconds.

The limit never applies to the action itself.