I found a simple script that uses Wish, but it only pastes the
selection in the terminal window where the script was invoked (if
there is one):
#! /bin/sh
exec wish "$0" "$@"
set buffer ""
catch {set buffer [selection get]}
puts $buffer
exit
"pasting the selection" not always makes sense for a "window".
What you could do is use xte to simulate a <Ctrl-V> or
<Shift-Insert> or <Middle-button>.
xdpyinfo can tell you the window id of the window that has the
focus. xwininfo -all and xprop can tell you more on that window
(like its class or name or the list of events it expects so you
can decide what key combination to use).
--
Stᅵphane
> Is it possible to write a program to paste the X selection at the text
> cursor in the window that has focus when the program is invoked? Or