How to paste the output/return of a script with a keybind?

Is there any Linux tool that enables the following? :

  1. Create a script like this (example):
from datetime import datetime

now = datetime.now()
timestamp = now.strftime("%Y-%m-%d %H:%M")
return timestamp

  1. Assign a keybind

  2. When the keybind it pressed, automatically paste the output of the script

1 Like

Check out espanso here: espanso.org
Not exactly an answer to what you are asking but does provide exactly what you are looking for.
Very flexible, useable and doesn’t cost anything.

1 Like

You don’t need a single tool. This is usually done with a small script plus a keybinding.

On X11, bind a key to run a script and pipe its output to the clipboard using xclip or xsel (via xbindkeys or your WM).

On Wayland, do the same but use wl-copy and your compositor’s built-in keybinding system (GNOME, KDE, Sway, Hyprland).

most users skip Python entirely and just do:
date +"%Y-%m-%d %H:%M" piped into the clipboard.

@Tasman Thanks for sharing. I had not come across Espanso before, but it looks like a solid fit for this use case. Dynamic date expansion on a trigger is exactly what the OP is describing.

Can I create custom keybword’s+script’s with it?

I think Gnome keybidns are buggy, I set one put nothing happens when I press the keybind