Skip to content

Instantly share code, notes, and snippets.

@smeech
Last active May 25, 2026 20:51
Show Gist options
  • Select an option

  • Save smeech/638c6007854f0ae90fcc0729722a9639 to your computer and use it in GitHub Desktop.

Select an option

Save smeech/638c6007854f0ae90fcc0729722a9639 to your computer and use it in GitHub Desktop.
[Delays] Espanso doesn't support replacements which include delays. A couple of alternatives. #espanso #bash #python
# Espanso doesn't support replacements which include delays
# A solution is to ignore Espanso's own replace and use another tool to inject characters
# Similar methods are available for Windows PowerShell using e.g.:
# (New-Object -ComObject wscript.shell).SendKeys
# Snippet to inject text using xdotool
- trigger: ":xd"
replace: "{{output}}"
vars:
- name: output
type: shell
params:
cmd: |
nohup bash -c '
xdotool type "Some text"
xdotool key KP_Enter
sleep 1.5
xdotool type "Some more text"
' > /dev/null 2>&1 &
# Snippet to inject text using Python
# https://pynput.readthedocs.io/en/latest/keyboard.html#controlling-the-keyboard
- trigger: ":pd"
replace: "{{output}}" # Redundant placeholder
vars:
- name: output
type: script
params:
args:
- python
- -c
- |
import time
from pynput.keyboard import Controller, Key
keyboard = Controller()
# Remove trigger characters (simulate pressing BackSpace three times)
for _ in ":pd": keyboard.tap(Key.backspace)
keyboard.type("Some text")
keyboard.tap(Key.enter)
time.sleep(1.5)
keyboard.type("Some more text")
# Supply dummy characters for Espanso to remove
keyboard.type(":pd")
# Alternative method for Python pynput which avoids the need to remove and
# retype the trigger
- trigger: :dothething
replace: "{{output}}"
vars:
- name: output
type: shell
params:
cmd: |
nohup python3 - << 'EOF' > /dev/null 2>&1 &
from pynput.keyboard import Controller, Key
import time; kb = Controller()
kb.type("command one\n")
time.sleep(0.5)
kb.type("command two\n")
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment