Advertisement
smeech

trigger_espanso.py

Aug 26th, 2024
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. # A Python script to invoke `espanso match exec -t <trigger>`, which gets around
  2. # Espanso trying to delete the trigger characters (which don't exist when called
  3. # in this manner) by injecting the characters first.
  4. # An alternative to using: `xdotool sleep 0.2 type <trigger>`
  5. # Either can be attached to a system hotkey.
  6.  
  7. #!/usr/bin/env python3
  8. import subprocess, sys, time
  9. from pynput.keyboard import Controller, Key
  10.  
  11. # Check if a command-line argument is provided
  12. if len(sys.argv) != 2:
  13.     print("Usage: python3 trigger_espanso.py <word>")
  14.     sys.exit(1)
  15. else:
  16.     word = sys.argv[1]
  17.  
  18. # Create an instance of the keyboard controller
  19. keyboard = Controller()
  20.  
  21. # Type the provided word into the active window
  22. keyboard.type(word)
  23.  
  24. # Run the Espanso command to trigger the match with the provided word
  25. command = f"espanso match exec -t {word}"
  26. subprocess.run(command, shell=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement