Skip to content

Environment Variables

Environment variables let you pass dynamic data into your forms without hardcoding values. You can access them in your form config using {{env.VARIABLE_NAME}}.

Espanso Dynamic Forms gives you access to:

  • System environment variables (like USERNAME, HOME, PATH)
  • Custom variables you pass via the --env argument
  • Built-in EDF variables (prefixed with EDF_)

Using Environment Variables

In the Data Section

Pre-fill form fields with environment variable values:

yml
schema:
  type: object
  properties:
    author:
      type: string

uischema:
  type: VerticalLayout
  elements:
    - type: Control
      scope: "#/properties/author"

data:
  author: "{{env.USERNAME}}"

template: |
  Author: {{author}}

When the form opens, the author field is pre-filled with the current user's name.

In the Template Section

Include environment data directly in your output:

yml
schema:
  type: object
  properties:
    message:
      type: string

uischema:
  type: VerticalLayout
  elements:
    - type: Control
      scope: "#/properties/message"

data:
  message: ""

template: |
  From: {{env.USERNAME}}
  Machine: {{env.COMPUTERNAME}}
  
  {{message}}

This adds the username and computer name to every output, regardless of what the user types.

In Espanso Triggers

Reference environment variables in your trigger's --form-config path:

yml
matches:
  - trigger: ':demo'
    replace: '{{output}}'
    force_mode: clipboard
    vars:
      - name: output
        type: script
        params:
          args:
            - C:/Program Files/Espanso Dynamic Forms/EDF.exe
            - --form-config
            - \{\{env.EDF_FORMS}}/demo.yml

The EDF_FORMS variable points to the bundled example forms, so this trigger loads the demo form from the installation directory.

Why the backslashes?

The backslashes (\{\{) escape the curly braces so Espanso passes them literally to Espanso Dynamic Forms instead of trying to process them itself. Alternatively, add inject_vars: false to your trigger. See Espanso's documentation for details.

Passing Custom Environment Variables

Use the --env argument to pass custom variables from your Espanso trigger:

yml
matches:
  - trigger: ':project'
    replace: '{{output}}'
    force_mode: clipboard
    vars:
      - name: output
        type: script
        params:
          args:
            - C:/Program Files/Espanso Dynamic Forms/EDF.exe
            - --form-config
            - C:/forms/project-note.yml
            - --env
            - PROJECT_NAME=MyApp
            - --env
            - TEAM=Backend

In your form config, access these with {{env.PROJECT_NAME}} and {{env.TEAM}}.

Multiple variables

Repeat --env for each variable you want to pass.

Debugging Environment Variables

To see all available environment variables while a form is open:

  1. Press Ctrl+Shift+I to open Developer Tools
  2. Look in the Console tab for the logged environment object

console-log.avif

Built-in Variables

EDF Variables

Espanso Dynamic Forms provides these variables automatically:

VariableDescriptionExample Value
EDF_EXECUTABLEFull path to the EDF executableC:/Program Files/Espanso Dynamic Forms/EDF.exe
EDF_INSTALLATION_DIRInstallation directoryC:/Program Files/Espanso Dynamic Forms
EDF_RESOURCESPath to bundled resourcesC:/Program Files/Espanso Dynamic Forms/resources/app.asar/dist
EDF_FORMSPath to bundled example formsC:/Program Files/Espanso Dynamic Forms/resources/app.asar/dist/forms
EDF_FORM_CONFIG_PATHThe raw --form-config value you passed{{env.EDF_FORMS}}/demo.yml
EDF_FORM_CONFIG_PATH_RENDEREDThe path after Liquid processingC:/.../forms/demo.yml
EDF_FORM_CONFIG_PATH_REALThe resolved path (resolves symlinks)C:/.../forms/demo.yml

Espanso Variables

If Espanso is installed and accessible, these variables are also available:

VariableDescriptionExample Value
ESPANSO_CONFIGPath to Espanso's config directoryC:/Users/YourName/AppData/Roaming/espanso
ESPANSO_PACKAGESPath to Espanso's packages directoryC:/Users/YourName/AppData/Roaming/espanso/match/packages
ESPANSO_RUNTIMEPath to Espanso's runtime directoryC:/Users/YourName/AppData/Local/espanso

System Variables

You also have access to all system environment variables like USERNAME, HOME, PATH, COMPUTERNAME, etc.