Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Set X clipboard contents

1 view
Skip to first unread message

Jan Keirse

unread,
Feb 16, 2003, 12:05:55 PM2/16/03
to
Hello,

I'm trying to get some text copied to the X clipboard from inside of code,
I'm currently trying it with clipboard append, but this does not seam to work.
Is it possible to get something on the clipboard? The text in question is not in
a widget so I can't just get it selected.

Thanks in advance,

Jan

--
Codito ergo sum - /(bb|[^b]{2})/ that is the Question
Jan Keirse: jan.k...@pandora.be Tel.: +32 51 22 11 82
Website: http://jankeirse.free.fr

Michael Schlenker

unread,
Feb 16, 2003, 12:22:44 PM2/16/03
to
Jan Keirse wrote:
> Hello,
>
> I'm trying to get some text copied to the X clipboard from inside of code,
> I'm currently trying it with clipboard append, but this does not seam to work.
> Is it possible to get something on the clipboard? The text in question is not in
> a widget so I can't just get it selected.

You must first call [clipboard clear] before using [clipboard append].
(read man n clipboard).

If that doesn't work, are you really using the clipboard or an other X
selection? If so read man n selection.

Michael Schlenker

Donal K. Fellows

unread,
Feb 17, 2003, 10:37:09 AM2/17/03
to
Jan Keirse wrote:
> I'm trying to get some text copied to the X clipboard from inside of code,
> I'm currently trying it with clipboard append, but this does not seam to work.
> Is it possible to get something on the clipboard? The text in question is not
> in a widget so I can't just get it selected.

Ultimately, the [selection] command is responsible for handling all that stuff
(the clipboard is just the CLIPBOARD selection) and the [clipboard] command is
just a "friendly" front-end to what you can do with [selection].

Note that if you are going to put something on the clipboard, you should start
out by doing [clipboard clear] because you don't really want to append to
whatever's already there, but rather use what you're about to put in.

Donal.
--
Donal K. Fellows http://www.cs.man.ac.uk/~fellowsd/ donal....@man.ac.uk
-- There are worse futures that burning in hell. Imagine aeons filled with
rewriting of your apps as WinN**X API will mutate through eternity...
-- Alexander Nosenko <n...@titul.ru>

Jan Keirse

unread,
Feb 17, 2003, 2:31:03 PM2/17/03
to
Donal K. Fellows <donal.k...@man.ac.uk> wrote:

> Jan Keirse wrote:
>> I'm trying to get some text copied to the X clipboard from inside of code,
>> I'm currently trying it with clipboard append, but this does not seam to work.
>> Is it possible to get something on the clipboard? The text in question is not
>> in a widget so I can't just get it selected.

> Ultimately, the [selection] command is responsible for handling all that stuff
> (the clipboard is just the CLIPBOARD selection) and the [clipboard] command is
> just a "friendly" front-end to what you can do with [selection].

The problem is I don't see a way to set the selection myself, from code. The
only way I can set the selection myself is by placing it in a widget and select
it.

I'll explain what exactly I want to do: I am writing a tk application that
creates some code (html, css or actually whatever I've added a plugin for) based
on some settings (the settings are made in a gui in tcl/tk). The intention is
that the code generated is not displayed inside the application (because it's
useless there) but is copied to the x clipboard. This way, I can just past it in
my editor by pressing the middle mouse button.
Can I do this with the selection and/or clipboard command? And if so, how
exactly? I thought this could be done with the clipboard command, but the code
doesn't seam to work, nothing gets into the clipboard (at least not the X one),
when I press the middle button in vim nothing gets pasted.

> Note that if you are going to put something on the clipboard, you should start
> out by doing [clipboard clear] because you don't really want to append to
> whatever's already there, but rather use what you're about to put in.

Yes, i've done that off course, I read man n clipboard (more than once actually
;-))

> Donal.
Kind regards,

Donal K. Fellows

unread,
Feb 18, 2003, 10:45:34 AM2/18/03
to
Jan Keirse wrote:
> I'll explain what exactly I want to do:

Always the path to enlightenment round here...

> I am writing a tk application that
> creates some code (html, css or actually whatever I've added a plugin for)
> based on some settings (the settings are made in a gui in tcl/tk). The
> intention is that the code generated is not displayed inside the application
> (because it's useless there) but is copied to the x clipboard. This way, I can
> just past it in my editor by pressing the middle mouse button.
> Can I do this with the selection and/or clipboard command? And if so, how
> exactly? I thought this could be done with the clipboard command, but the code
> doesn't seam to work, nothing gets into the clipboard (at least not the X
> one), when I press the middle button in vim nothing gets pasted.

There are several things that might be going wrong here. But the three to think
about are really:
* Data never makes it into the clipboard.
* Data makes it into the clipboard but the clipboard owner dies before it gets
transferred out again.
* Data gets put in with the wrong type.

We can check the first one with [selection own -selection CLIPBOARD] after we've
manipulated the clipboard. If that replies with a widget, we know we're the
owner. But you might get into problems if there is a general clipboard manager
on the display. On the other hand, if there is a clipboard manager about, then
it can look after keeping the clipboard contents alive after the app that
generated them died (which is a problem otherwise.)

Sounds like the third problem doesn't actually apply here. ;^)

"I wouldn't just call you wrong. I'd go further and call you an argumentative
net-kook idiot who can't do his own research before opening his mouth and
yammering bullshit." -- Theo de Raadt <der...@zeus.theos.com>

Jan Keirse

unread,
Feb 18, 2003, 11:02:56 AM2/18/03
to
Donal K. Fellows <donal.k...@man.ac.uk> wrote:

Here's some code I've used:
proc copie_X { } {
global selectedfont examplesize
puts [selection own -selection CLIPBOARD]
clipboard clear
clipboard append -- "-*-$selectedfont-*-*-*-*-$examplesize"
puts [selection own -selection CLIPBOARD]
}

This code puts two empty lines on the terminal from wich I run the script if the
procedure is executed, the contents of the clipboard isn't changed.
Also, the application producing the code (-*-$selectedfont-*-*-*-*-$examplesize)
is still on when I try to paste the copied text.

Joe English

unread,
Feb 18, 2003, 11:08:42 AM2/18/03
to
Jan Keirse wrote:

>The problem is I don't see a way to set the selection myself, from code. The
>only way I can set the selection myself is by placing it in a widget and select
>it.

You can find some sample code for user-defined selection
handlers on the Wiki under "Primary Selection vs. the Clipboard":

<URL: http://wiki.tcl.tk/1217 >

The basic procedure is: (1) set up selection handlers for
each supported target type (typically just STRING) with
[selection handle], then (2) claim ownership of the selection
with [selection own].

When another application requests the selection value, Tk
will call the registered selection handler.

>I'll explain what exactly I want to do: I am writing a tk

>application that creates some code [...] The intention is that the


>code generated is not displayed inside the application (because
>it's useless there) but is copied to the x clipboard. This way,
>I can just past it in my editor by pressing the middle mouse
>button.

In most X applications, the middle mouse button uses
the PRIMARY selection, not the CLIPBOARD. The aforecited
Wiki page talks about this in more detail.


Hope this helps,

--Joe English

jeng...@flightlab.com

Jan Keirse

unread,
Feb 19, 2003, 8:10:35 AM2/19/03
to
Joe English <jeng...@flightlab.com> wrote:

> Jan Keirse wrote:

>>The problem is I don't see a way to set the selection myself, from code. The
>>only way I can set the selection myself is by placing it in a widget and select
>>it.

> You can find some sample code for user-defined selection
> handlers on the Wiki under "Primary Selection vs. the Clipboard":

> <URL: http://wiki.tcl.tk/1217 >

> The basic procedure is: (1) set up selection handlers for
> each supported target type (typically just STRING) with
> [selection handle], then (2) claim ownership of the selection
> with [selection own].

> When another application requests the selection value, Tk
> will call the registered selection handler.

:-) That does the thing! Thank you very much, it was very helpfull!

0 new messages