Last active
February 4, 2025 19:04
-
-
Save smeech/83c17786c9cad2492fd9a622d877bb0c to your computer and use it in GitHub Desktop.
[Trigger] A Python script to invoke `espanso match exec -t (trigger)`, which gets around Espanso trying to delete the trigger characters (which don't exist when called in this manner) by injecting the characters first. An alternative to using: `xdotool sleep 0.2 type (trigger)`. Either can be attached to a system hotkey. #espanso #python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A Python script to invoke `espanso match exec -t <trigger>`, which gets around | |
# Espanso trying to delete the trigger characters (which don't exist when called | |
# in this manner) by injecting the characters first. | |
# An alternative to using: `xdotool sleep 0.2 type <trigger>` | |
# Either can be attached to a system hotkey. | |
#!/usr/bin/env python3 | |
import subprocess, sys, time | |
from pynput.keyboard import Controller, Key | |
# Check if a command-line argument is provided | |
if len(sys.argv) != 2: | |
print("Usage: python3 trigger_espanso.py <word>") | |
sys.exit(1) | |
else: | |
word = sys.argv[1] | |
# Create an instance of the keyboard controller | |
keyboard = Controller() | |
# Type the provided word into the active window | |
keyboard.type(word) | |
# Run the Espanso command to trigger the match with the provided word | |
command = f"espanso match exec -t {word}" | |
subprocess.run(command, shell=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment