X selection tools in debian 

cmd:xsel 

Package: xsel
Description: More than just cat for the X selection.

XSel is a command-line program for getting and setting the contents of the X selection. Normally this is only accessible by manually highlighting information and pasting it with the middle mouse button.

cmd:xclip 

Package: xclip
Description: command line interface to X selections

xclip is a command line utility that is designed to run on any system with an X11 implementation. It provides an interface to X selections ("the clipboard") from the command line. It can read data from standard in or a file and place it in an X selection for pasting into other X applications. xclip can also print an X selection to standard out, which can then be redirected to a file or another program.

Homepage: http://people.debian.org/~kims/xclip/[]

Using xclip 

Copy your uptime into the selection for pasting:
uptime | xclip
Copy your password file for pasting:
xclip /etc/passwd
Save some text you have Edit | Copied in a web browser:
xclip -o -sel clip > webpage.txt
Open a URL selected in an email client
mozilla `xclip -o`
Copy XA_PRIMARY to XA_CLIPBOARD
xclip -o | xclip -sel clip

cmd:xcutsel 

interchange between cut buffer and selection

Synopsis

xcutsel [ -toolkitoption ...] [-selection selection] [-cutbuffer number]

Description

The xcutsel program is used to copy the current selection into a cut buffer and to make a selection that contains the current contents of the cut buffer. It acts as a bridge between applications that don't support selections and those that do.

By default, xcutsel will use the selection named PRIMARY and the cut buffer CUT_BUFFER0. Either or both of these can be overridden by command line arguments or by resources.

capturing terminal scrollback buffer? 

Newsgroups:  gmane.linux.debian.user
Date:        Sat, 30 Sep 2006 12:30:09 -0400
> anybody know how to capture the contents of a terminal scrollback
> buffer? i've got about 1000 lines of debug stuff from a network
> problem that I want to save, but its just sitting in the scroll back
> buffer of an aterm. argh! how do I get it out of there without
> copy/pasting it one screen at a time?

Here's how I do it on aterm:

Drag scrollbar up (back) to first desired line. Start selecting a few characters of text (left mouse button, drag…). Let go of mouse button. Drag scrollbar down to end of desired line. Right click. Let go of mouse button. All desired text is selected. Now you can paste it where you like…

$ cat > textbuffer

Middle-click to paste, etc.

Much easier to do than to describe.

Ralph Katz

capturing terminal scrollback buffer? 

> buffer of an aterm. argh! how do I get it out of there without
> copy/pasting it one screen at a time?

For the future, you may want to take a look at gnu/screen.

When you are running your terminal sessions under gnu/screen and you suddenly realize that you need to take a screen dump on the fly, all you need to do is:

The -h flag causes gnu/screen to write the contents of the current display as well as the contents of the scrollback buffer to the specified file.

The point is that it's always there ready for you to use .. you don't need to do anything special prior to starting your debugging session & whatnot.

Needless to say that there a tons of other great features in gnu/screen such as advanced copying & pasting between terminal sessions and activating/deactivating session logging on the fly .. among many others.

For a terse introduction to gnu/screen's capabilities you could read the following article :

http://jmcpherson.org/screen.html

For an in-depth description of gnu/screen's many talents I'm afraid that there is no advanced tutorial that I am aware of and you will have to study the excellent but somewhat unfriendly manual (man screen).

cga2000

Do something with selected text? 

Newsgroups: comp.os.linux.x
Date: Mon, 27 Jan 2003 02:05:49 GMT
: Is there a way to execute a script/program on selected text?

There are several ways. Most trivially, if you have a URL selected, you can simply point at a netscape window and middle-click, and netscape will open that URL. Unix/linux netscapes are set up to do that as-is.

More complicated, note that if the current X selection has the general appearance of a URL, KDE normally offers to open that URL for you with mozilla/konqueror or whatnot. As soon as you stop dragging to select, if you selected something starting with http://, it'll pop up a dialogue to ask you what to do with it. You can customize this. If you aren't already using KDE, adopting it just for this is a bit overkill, but the facility is there, and scriptable (which netscape is far less so).

The two ways I most often manipulate the X selection are with use tcl/tk (or other bindings of the tk toolkit, like perl/tk), and with use of a program like xselection.

In tcl/tk, there's a "selection" command, which can be used to return the current X selection inside tcl scripts. Or perl, or whatever. See http://tcl.sourceforge.net/faqs/ A shell command to demonstrate it minimally might be

echo 'puts -nonewline [selection get]; exit' | wish -

or as a separate tcl script in linux

#!/usr/bin/wish -f
puts -nonewline [selection get]
exit

These both will write the value of the current X selection to stdout and then exit. Therefore, you can write shell (or tcl) scripts to do whatever you want to the X selection, and most window managers have a way to execute arbitrary shell scripts via pull-down menu or buttonclick on the background, or whatever. If you select a URL, and then in a wish session (ie, the tcl/tk script interpreter, the (wi)ndowing (sh)ell) you can type

exec netscape -remote "openURL([selection get]"

or if you have the above script stored in file "selectionget", a normal shell command

netscape -remote "openURL(`selectionget`)"

and either of these will open the appropriate page. Or consider a wish script like this one

#!/usr/bin/wish -f
pack [button .openURL -text openURL -command \
      {exec netscape -remote "openURL([selection get])"}]

It will put up a button on which you can click to open the the current X selection as a URL with netscape.

In short, tcl/tk is a very effective way to script all kinds of X windows interactions, and integrate them into unix-style pipelines, or into normal unix scripting methods.

Next consider xselection.

ftp://ftp.x.org/R5contrib/xselection.tar.Z

If you download and compile it (in the usay way for contributed X apps), you use it from the shell to both get and set the X named selections, and cutbuffers. For example, the shell case above can be done like so

netscape -remote "openURL(`xselection PRIMARY`)"

Not as powerful or general-purpose as tcl/tk, but it does a good job of manipulating the various ways programs can cut/paste/select in X in normal unix scripts or pipelines.

Wayne Throop

cmd:xcb 

Info 

Do you ever wish you could cut two or more separate pieces of text at once from a window? Do you ever need to save the output from one command for reuse in several subsequent tasks? Do you ever find yourself wanting some easy means of globally exporting data, e.g. to a parent shell, to another xterm or application, or to another machine or user? If you answer yes to any of these questions, then xcb is for you.

Xcb provides access to the cut buffers built into every X server. It allows the buffers to be manipulated either via the command line, or with the mouse in a point and click manner. The buffers can be used as holding pens to store and retrieve arbitrary data fragments, so any number of different pieces of data can be saved and recalled later. The program is designed primarily for use with textual data.

Source 

ftp://ftp.x.org/contrib/utilities/xcb-2.3.README

xterm selection 

Newsgroups: comp.unix.shell
> Is it possible to make xterm select a whole word ( file.txt ) for example
> when I double click it, instead of the part before the dot only ?

man xterm:

charClass (class CharClass)
        Specifies comma-separated lists of  character  class
        bindings  of  the  form [low-]high:value.  These are
        used in determining which sets of characters  should
        be  treated  the same when doing cut and paste.  See
        the section on specifying character classes.

Thomas E. Dickey

xfilesel 

Usage 

usage:  xfilesel [-f name] [-selection name]
   -file name - path of clipboard file (default value: ~/.clipboard),
        for example: -f /dev/tty1, -f /home/mc/.cedit/cooledit.clip
   -selection name - name of the selection to use. The default is PRIMARY.

Info 

The xfilesel program is used to copy the X selection into a file and to copy a file contents to the X selection. It acts as a bridge between applications that support selections and console applications (for example with default Midnight Commander clipboard file ~/.cedit/cooledit.clip).

Source 

http://freshmeat.net/projects/xfilesel http://freshmeat.net/projects/xfilesel/download/xfilesel.tar.gz

http://www.opennet.ru/xfilesel/

Installation 

The installation procedure is

1) xmkmf
2) make
3) make install

On linux 

$ xmkmf
mv -f Makefile Makefile.bak
imake -DUseInstalled -I/usr/X11R6/lib/X11/config
$ make
gcc -O2 -g -Wall     -I/usr/X11R6/include   -Dlinux -D__i386__ -D_POSIX_C_SOURCE=199309L -D_POSIX_SOURCE -D_XOPEN_SOURCE=500L -D_BSD_SOURCE -D_SVID_SOURCE   -DFUNCPROTO=15 -DNARROWPROTO     -c -o xfilesel.o xfilesel.c
xfilesel.c:3: warning: `/*' within comment
xfilesel.c:5: warning: `/*' within comment
xfilesel.c:93: warning: return-type defaults to `int'
xfilesel.c:275: warning: return type of `main' is not `int'
rm -f xfilesel
gcc -o xfilesel -O2 -g -Wall      -L/usr/X11R6/lib xfilesel.o -lXaw -lXmu -lXt -lSM -lICE -lXext -lX11
$ make -n install
make: *** Warning: File `xfilesel' has modification time in the future (2000-09-03 16:15:13 > 2000-09-03 16:07:45)
if [ -d /usr/X11R6/bin ]; then set +x; \
else (set -x; mkdir -p /usr/X11R6/bin); fi
install -c -s  xfilesel /usr/X11R6/bin/xfilesel
echo "install in . done"

Configuration & Twisting 

On Solaris

$ xmkmf
imake -DUseInstalled -I/opt/gnu/lib/X11/config
"Imakefile.c", line 10: Can't find include file Imake.tmpl
imake: Exit code 2.
  Stop.

manually invoke:

imake -DUseInstalled -I/shared/openwin/lib/X11/config/
$ make
cc -O -Xc -xF -xcg92    -I/usr/openwin/include  -Dsun -Dsparc -DSVR4 -DSYSV    XkbClientDefines   -c xfilesel.c -o xfilesel.o
/usr/ucb/cc:  language optional software package not installed

Comments 

It's a GUI based program. need to click on the buttons.

xv_get_sel alike tools for Linux 

Newsgroups: comp.os.linux.misc
> > >I'm looking for xv_get_sel alike tools for Linux.
> > >
> > Would this be something like xclipboard maybe (standard with X)?
> > Then there's xfilesel which I guess copies a selection to a file
> > and back to an X selection.
>
>Thanks, what I am really looking for is *command line* tools so that
>I can easily use them within my script. Sorry I didn't make myself
>clear at the first place.

The closest thing I found so far is xsel. Apparently it can be used in scripts and whatnot. I only gave it a quick look-at just now. Even though it's command line some little window pops up and then exits. Not sure what that's for yet. Still not the same as xv_get_sel.

http://www.niksula.cs.hut.fi/~vherva/xsel/

It's a single xsel.c file.

cmd:xsel 

Usage 

netscape -remote "openURL(`xsel -p`, new-window)" &

compile: 

Linux:

gcc xsel.c -O6 -o xsel -lX11 -lXt -lXaw -L /usr/X11R6/lib/

Solaris:

gcc xsel.c -O6 -o xsel -lX11 -lXt -lXaw -lXmu -L /usr/X11R6/lib/

Install 

Linux:

mv ~/dl/mustH_b/xwin/xsel /opt/bin

Solaris:

mv xsel ~/local/bin/