Skip to main content

Snippets

A snippet is a named piece of steps or script that isn't tied to any trigger. Actions, before and after scripts, global events and other snippets run it by name. Write something once as a snippet, and every action that calls it uses the same copy: change the snippet, and they all change.

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
Your snippets
Center window
Used by 2
Paste plain text
+ New
Snippets
Center window
Center window
Windows
Display only. It doesn't change how the snippet runs.
Script
SnippetExecuteScript("Center window");
StepsScript
1Center windowTarget window
Called by
Swipe Left
Browser: before script

The snippet list​

The list shows every snippet in the library, under a heading per category: categories A–Z, then Uncategorised, and A–Z by name inside each. A snippet that something calls shows Used by and the number of callers.

  • + New adds a snippet named New snippet in the selected snippet's category, written as Steps.
  • The duplicate button beside + New copies the selected snippet under a new, unique name.
  • The delete button on a row deletes a snippet (Deleting a snippet).

Name and category​

  • Name ① is how callers find the snippet. It must be unique across the whole library, whatever the category, and two names that differ only in upper and lower case count as the same. It can't contain a double quote, a backslash or a control character. A name that breaks a rule is shown in red with the reason, and goes back to the old name when you leave the box.
  • Renaming a snippet rewrites every call that names it in quotes, everywhere in your configuration (Who calls a snippet).
  • Category ② only groups the list. It doesn't change how the snippet runs.

What the snippet does​

Written as chooses Steps or Script, the same as for an action (Steps, Script and AutoHotkey). Switching from Steps to Script offers to translate the steps, as it does on the Actions page.

  • In Steps, the editor is the same as an action's (The Steps editor).
  • In Script, Check syntax checks the script with the engine's own compiler. It reports Parses OK with the line count, or the first error, and underlines the problem in the editor.
  • AutoHotkey is offered only for a snippet that already runs as AutoHotkey.
  • There is no button to run a snippet here. To try steps safely, use the Sandbox.
note

Advanced mode. Above the editor, the call that runs this snippet ③ is shown in Script form, with a button that copies it.

Calling a snippet​

A snippet runs when a step or a script calls the builtin SnippetExecuteScript with its name:

  • In Steps, add a Run a snippet step (SnippetExecuteScript) from the list of all builtins (Adding steps) and type the snippet's name as its Name.
  • In Script, write the call:
SnippetExecuteScript("Center window");

How it runs:

  • The caller waits until the snippet finishes, then continues.
  • The snippet sees what started the caller (its target window, gesture and so on), so Target window inside a snippet is the caller's target window.
  • The snippet has its own variables. It can't read the caller's, and the caller can't read its.
  • The name must match exactly, including upper and lower case. If no snippet has the name, nothing runs and the call gives false.
  • The call gives true only when the snippet ran to the end. It also gives false when the snippet is empty, has an error or is stopped.
  • A snippet can call other snippets. Nothing stops a snippet from calling itself, so make sure such a chain ends.

Who calls a snippet​

The Called by card ④ lists every action, before or after script, global event (even a turned-off one) and snippet that calls this snippet. A global event is marked Global event, and a snippet Snippet.

Only calls that write the snippet's name out in quotes are found. A call that builds the name while it runs is not listed, and a call inside a comment is. AutoHotkey bodies are not searched.

Deleting a snippet​

You can't delete a snippet while anything listed under Called by still calls it. The delete button then shows Can't delete with the list of callers; change or remove those calls first. A snippet nothing calls is deleted after a confirmation.

A call the list can't see (a name built while the script runs) is not protected: if you delete that snippet, the call finds nothing and gives false.

Snippets from elsewhere​

  • Create Snippet on the Recorder page turns a recording into a snippet.
  • Save as snippet on the Sandbox page saves the steps or script you tried there.

Both open the new snippet on this page with the cursor in its Name, ready to rename. A name already taken gets -1, -2 and so on added.