Table of Contents

smudgy:core — Saved automations

Generated from smudgy v0.3.5 (smudgy-core.d.ts @ cfcea3b156f6). Index: scriptref.

Create, edit, and delete the saved aliases/triggers/hotkeys (the ones shown in the automations window) from a script, via userAutomations. Saved automations run outside any sandbox, so a sandboxed package can never access them: writing one would let the package run code outside its sandbox. For the automations scripts create with the create* functions, see automations.

userAutomations

export const userAutomations: UserAutomations;

Manage the saved automations (see UserAutomations).

UserAutomations

export interface UserAutomations {
  aliases: SavedAutomationRegistry<SavedAlias, SavedAliasHandle>;
  triggers: SavedAutomationRegistry<SavedTrigger, SavedTriggerHandle>;
  hotkeys: SavedAutomationRegistry<SavedHotkey, SavedHotkeyHandle>;
}

Create and edit the saved automations (the aliases, triggers, and hotkeys shown in the automations window), as opposed to the ones scripts create with createAlias/createTrigger/createHotkey. One SavedAutomationRegistry per kind.

Not available to sandboxed packages: saved automations run outside any sandbox, so writing one would let a package run code outside its own.

SavedAutomationRegistry

export interface SavedAutomationRegistry<Def, Handle> {
  save(name: string, def: Def): Handle;
  get(name: string): Handle | undefined;
  list(): string[];
  exists(name: string): boolean;
  delete(name: string): boolean;
}

Manage one kind of saved automation. save creates or replaces and returns a handle; get returns a handle to an existing name; list/exists inspect; delete removes. Every write is saved to disk, takes effect in this session, and reloads the server's other sessions.

SavedAutomationHandle

export interface SavedAutomationHandle<Def> {
  readonly name: string;
  def(): Def;
  refresh(): boolean;
  update(patch: Partial<Def>): boolean;
  delete(): boolean;
}

A handle to one saved automation, returned by a registry's save/get. Reads are a snapshot: def() returns the definition as last read, and refresh() re-reads it from disk. update() and delete() write to disk and reload the server's other sessions.

SavedAlias

export interface SavedAlias {
  pattern: string;
  script?: string;
  enabled?: boolean;
  language?: ScriptLang;
  package?: string;
}

A saved alias, as stored in aliases.json and shown in the automations window.

SavedTrigger

export interface SavedTrigger {
  patterns?: string[];
  rawPatterns?: string[];
  antiPatterns?: string[];
  script?: string;
  enabled?: boolean;
  prompt?: boolean;
  language?: ScriptLang;
  package?: string;
}

A saved trigger, as stored in triggers.json and shown in the automations window.

SavedHotkey

export interface SavedHotkey {
  key: string;
  modifiers?: string[];
  script?: string;
  enabled?: boolean;
  language?: ScriptLang;
  package?: string;
}

A saved hotkey, as stored in hotkeys.json and shown in the automations window.

SavedAliasHandle

export type SavedAliasHandle = SavedAutomationHandle<SavedAlias>;

SavedTriggerHandle

export type SavedTriggerHandle = SavedAutomationHandle<SavedTrigger>;

SavedHotkeyHandle

export type SavedHotkeyHandle = SavedAutomationHandle<SavedHotkey>;

ScriptLang

export type ScriptLang = "plaintext" | "js" | "ts";

How a saved automation's script body runs: "js"/"ts" execute it as code; "plaintext" (the default) sends it as a literal command template.


Script API reference · smudgy:core — Sessions & output · smudgy:core — Lines & buffer · smudgy:core — Events · smudgy:core — Automations · smudgy:core — Panes · smudgy:widgets · Mapper · smudgy:params