smeech

Delays in replacements

Aug 16th, 2024 (edited)
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 1.65 KB | None | 0 0
  1. # Espanso doesn't support replacements which include delays
  2. # A solution is to ignore Espanso's own replace and use another tool to inject characters
  3. # Similar methods are available for Windows PowerShell using e.g.:
  4. # (New-Object -ComObject wscript.shell).SendKeys
  5.  
  6.   #  Snippet to inject text using xdotool
  7.   - trigger: ":xd"
  8.     replace: "{{output}}" # Redundant placeholder
  9.     vars:
  10.       - name: output
  11.         type: shell
  12.         params:
  13.           cmd: |
  14.            # Remove trigger characters
  15.             xdotool key BackSpace BackSpace BackSpace
  16.             xdotool type "Some text"
  17.             xdotool key KP_Enter
  18.             sleep 1.5
  19.             xdotool type "Some more text"
  20.             # Supply dummy characters for Espanso to remove
  21.             xdotool key Return type ":xd"
  22.  
  23.   #  Snippet to inject text using Python
  24.   #  https://pynput.readthedocs.io/en/latest/keyboard.html#controlling-the-keyboard
  25.   - trigger: ":pd"
  26.     replace: "{{output}}" # Redundant placeholder
  27.     vars:
  28.       - name: output
  29.         type: script
  30.         params:
  31.           args:
  32.            - python
  33.             - -c
  34.             - |
  35.              import time
  36.               from pynput.keyboard import Controller, Key
  37.               keyboard = Controller()
  38.               # Remove trigger characters (simulate pressing BackSpace three times)
  39.               for _ in ":pd": keyboard.tap(Key.backspace)
  40.               keyboard.type("Some text")
  41.               keyboard.tap(Key.enter)
  42.               time.sleep(1.5)
  43.               keyboard.type("Some more text")
  44.               # Supply dummy characters for Espanso to remove
  45.               keyboard.type(":pd")
Add Comment
Please, Sign In to add comment