The simplest way is probably to always own the clipboard selection.
This has several downsides: You are responsible for the clipboard, and some clipboard contents might be lost, so this is not bullet-proof.
proc readclip {} {
after 50 {
puts [set cnt [clipboard get]]
clipboard clear
clipboard append $cnt
selection own -command readclip -selection CLIPBOARD .
selection handle . [list string range $cnt]
}
}
selection own -command readclip -selection CLIPBOARD .
When readclip
is invoked, the new application has requested the ownership over the clipboard, but it does not yet have the ownership, so we wait a bit to let it get it, setup everything etc.
Also note that if more than 1 application does this, both applications "battle" over the ownership of the clipboard, which is a bad thing.