Created
June 18, 2025 15:40
-
-
Save smeech/178882d1320067473f917d2879760826 to your computer and use it in GitHub Desktop.
[Implement multiple possible returns for a choice form variable] A minimal script workaround to Espanso's inability to return a variable number of choices. #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
# Via https://chatgpt.com/share/6852dd0d-dcd4-8012-849f-623787d8408a | |
# In response to https://github.com/espanso/espanso/issues/2360 | |
- trigger: ":checklist" | |
replace: "{{output}}" | |
vars: | |
- name: output | |
type: script | |
params: | |
args: | |
- python | |
- -c | |
- | | |
import tkinter as tk | |
from tkinter import ttk | |
items = [ | |
"One", | |
"Two", | |
"Three", | |
"Four", | |
] | |
selected = [] | |
def on_submit(): | |
selected.extend(item for var, item in zip(vars, items) if var.get()) | |
root.quit() | |
root = tk.Tk() | |
root.title("Select Items") | |
root.geometry("200x200") | |
vars = [] | |
for item in items: | |
var = tk.BooleanVar() | |
cb = ttk.Checkbutton(root, text=item, variable=var) | |
cb.pack(anchor='w') | |
vars.append(var) | |
ttk.Button(root, text="Submit", command=on_submit).pack(pady=10) | |
root.mainloop() | |
root.destroy() | |
print(", ".join(selected)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment