I’ve recently bound a key sequence in my window manager (Xmonad) to grab the active window ID with xdotool
and then spawn an Emacs frame and run an elisp command, passing it the window ID as an argument.
The Emacs command does something along vaguely similar lines to your program to interact with the user and fetch a password, and it puts the result into the X clipboard and then uses xdotool
again to type ctrl+v into the original window.
I then tell Emacs to hide the frame and sleep for a second before deleting the frame completely, which gives the target application plenty of time to obtain the clipboard contents (which X has to obtain from the window/frame which currently owns the clipboard) before they’re gone. I’m not using any clipboard manager program, so I’m vaguely convinced that the passwords being pasted aren’t being captured and retained anywhere else, and I rather like that (assuming sensible usage) I never see the password at all.
Obviously that only works if ctrl+v is “paste” for the target application, but right now I’m only using this for some web browser forms. I could undoubtedly obtain more window data and choose the appropriate keystroke conditionally.
I hadn’t used xdotool
before, but it seems like it could be very useful.