[Date Prev][Date Next][Subject Prev][Subject Next][ Date Index][ Subject Index]

accessing the Linux clipboard...



From: "Raphael Tennenbaum" 
>Subject: accessing the Linux clipboard
>any linuxyers know how to read/write this? I seem to remember some discussion
>a few years back.

Rafe,

Paul Lagasse and I worked out different methods, either of which might work for you.

To quote Paul:
----------------------------
In an attempt to avoid having to open a file to transfer text to/from
XyWrite in Linux, I have come up with with what I think is a somewhat
easier, more automated kludge for transfering text to and from the Linux
clipboard when running XyWrite under Dosemu. This works, at least, in my
Ubuntu installation. It does involve a more complicated one-time setup.

To start, in my keyboard file, I have two lines in my CTRL+ALT table
(keys k and v, respectively, as my c was taken years ago):

37=BX,(,s,a,s,/,n,v, ,\,c,l,i,p,.,t,x,t,)
47=BX,(,m,e, ,\,c,l,i,p,.,t,x,t,)

and I have the file "clip,txt" in my Ubuntu home directory (which under
Dosemu is d:\)

I also have installed xsel, a command-line program that can manipulate
the clipboard (see http://www.vergenet.net/~conrad/software/xsel/). I
used "sudo apt-get install xsel" at a terminal window to install xsel. I
found xsel after some googling.

I wrote two tiny script files; both were written with gedit. You should
note that these two "scripts" now bring my Linux total to two, and I am
basically mimicking what I have read in a manual or two. But they do work.

The first script is toxyclip.sh, and is in its five-line entirety:

#! /bin/bash
#
# copies clipboard contents to ~/clip.txt for XyWrite
#
xsel -b >~/clip.txt

The last line ends with a carriage return. "-b" directs xsel to act on
the clipboard.

The second script is tosysclip.sh. Its contents are

#! /bin/bash
#
# copies clipboard contents from XyWrite's ~/clip.txt to system clipboard
#
xsel -b <~/clip.txt

After writing and saving both scripts, I opened a terminal window and
made the scripts executable by issuing the commands:

chmod u+x toxyclip.sh
chmod u+x tosysclip.sh

I exited the terminal, and rightclicked the desktop and chose "Create
launcher."

In the Create Launcher window, the "Type" is Application, for the
"Command" I browsed for tosysclip.sh, and for the "Name" I entered "To
System Clipboard". For toxyclip.sh, I named it "To XyWrite Clipboard." I
put both completed launchers on the desktop down in one corner so they
would be visible when running XyWrite in a Dosemu window.

To clip to the system, I highlight the text in XyWrite, hit ctrl+alt+k
twice (yes, twice, for some unknown reason: see below), and doubleclick
the "To System Clipboard" icon on my desktop. Then I can use ctrl+v to
insert the text (the Kludge Cargo, if you will) into an editor in Ubuntu.

To clip from say "Firefox," I highlight the text, do ctrl+c, then
doubleclick "To Xywrite Clipboard," and then do ctrl+alt+v to insert the
text in XyWrite.

You save time by having xsel write to and from clip.txt. You don't to
wait for gedit to open clip.txt, don't have to paste the clipboard
contents into clip.txt, and don't have to save clip.txt. All that is
replaced with two mouseclicks (two in my case; maybe just one click for
you).

The carriage return/line feed issue can mess with the text. **And for
some reason I have trouble copying from XyWrite to "clip.txt" using
ctrl+alt+k, and have to hit it twice (the first time I hit it, Dosemu
adds "keyboard grab" to its title bar, the second time I hit it, XyWrite
notes "Done." I seem to have no trouble inserting text into a XyWrite
file, except for the carriage return/line feed issue.
--------------------------------

Here is my method:
--------------------------------
Paul's method above certainly works for cutting and pasting in and out of Xywrite in Linux, but it
requires too many keystrokes and mouse actions for my taste.

However, his kludge suggestion to clip into a file, clip.txt, save it, and then MErge the file into
Xywrite, was brilliant, and led me to come up with my own cut-and-paste kludge that, by using a
Linux macro program, reduces the number of keystrokes for placing text into Xywrite to two, the same
as you would have with any program.

The macro program is called Xmacros. It is part of the Debian package, which means it should also be
available in Ubantu. (At the command prompt: sudo apt-get install xmacros) I should also note that
Xmacros has been incredible useful for running a lot of other macros in all my Linux programs,
thereby reducing the number of repetitive keystrokes I have to do.

Xmacros allows you to create macros two ways. 1. You can run a subprogram, xmacrorec2, to record your keystrokes. I have had problems getting this to function properly. 2. You can write the macro in any plain text editor. The commands are simple (see http://xmacro.sourceforge.net/), and I have found this method to be quick and easy.

To make the whole operation work I keep a text editor with the file clip.txt open at all times. I
use Kwrite, but any plain text editor will do. In Linux, it is easy to place this open file/program
in Desktop 4, out of the way, where it functions as my silent dos clipboard.

The full macro for copying text to Xywrite is as follows. Note that anything after the pound sign is
a comment and can be deleted:

# Switches from command prompt to window where text is selected:
KeyStrPress Alt_L
KeyStrPress Tab
KeyStrRelease Tab
KeyStrRelease Alt_L
# Copies the selection into Linux clipboard:
KeyStrPress Control_L
KeyStrPress C
KeyStrRelease C
KeyStrRelease Control_L
# Switches to Desktop 4, where I keep clip.txt open all the time:
KeyStrPress Control_L
KeyStrPress Alt_L
KeyStrPress 4
KeyStrRelease 4
KeyStrRelease Alt_L
KeyStrRelease Control_L
# Pastes selection into clip.txt:
KeyStrPress Control_L
KeyStrPress R
KeyStrRelease R
KeyStrRelease Control_L
# Saves clip.txt:
KeyStrPress F12
KeyStrRelease F12
# Selects all (necessary to make future selections work):
KeyStrPress Control_L
KeyStrPress A
KeyStrRelease A
KeyStrRelease Control_L
# Switches back to Desktop 1, back where I started:
KeyStrPress Control_L
KeyStrPress Alt_L
KeyStrPress 1
KeyStrRelease 1
KeyStrRelease Alt_L
KeyStrRelease Control_L

I created a text file of the above and named it doscopy.macro.

I then used the KDE menu editor to create a shortcut to doscopy.macro in the Start menu. (Sidebar: I
use Debian Etch with KDE as my Xwindows GUI. The KDE menu editor allows me to create a menu of
program shortcuts accessible by pressing the Start key. I put all my macro shortcuts in Start -
System - Macros. Each macro gets its own shortcut menu item.) For the doscopy shortcut the command
line should read:

cat /home/bob/programs/macros/doscopy.macro | xmacroplay -d 15:0

The "-d 15:0" puts a 15 millisecond delay between each command. I have found with testing
that this can sometimes be as low as 0, and sometimes must be as high as 30, for the macro to work
reliably. I try to keep the number low to speed things along. It just requires a little
experimentation to find the right number.

I also check "run in terminal" in the shortcut options. I then assign a shortcut key to
this shortcut menu item. For my doscopy.macro, I gave it Ctrl-Alt-C.

In my Xywrite 3.55 keyboard.kbd file, I created a keyboard macro at Ctrl-Space, like so:

57=BC,m,e, ,E,:,\,x,y,w,r,i,t,e,4,\,x,y,4,\,c,l,i,p,.,t,x,t,XC,CH

In my Xywrite 4 xy4.kbd file, I created the following keyboard macro for Ctrl-Space:

57=BX,(,m,e, ,D,:,\,x,y,w,r,i,t,e,4,\,x,y,4,\,c,l,i,p,.,t,x,t,)

Thus, to paste some text into either Xywrite 3.55 or Xywrite 4, I select the text in any Linux
program and press Ctrl-Alt-C. Then in Xywrite I press Ctrl-Space and the text is inserted. Very
simple.

Sidebar: I use DosBox as my Dos emulator. I have found it very stable, reliable, easy to use, and
very flexible. However, this system should also work very easily with Dosemu.

As for pasting out of Xywrite into Linux, I don't need to do it very often. If I do, I find I
generally have to paste the whole file. In that case it is easier to save it, and then upload it
directly using another program.

I also use Xmacros to run two macros for allowing me to write all my emails in Xywrite. With one
keystroke I tell my email program to reply, quote the text of the original email, and then using
clip.txt cut and paste this into Xywrite. Once I've finished writing my email it takes two
keystrokes to cut and paste my written email out of Xywrite and back into my email program, ready to
send. If anyone is interested I can write up the details on how these macros work for the listserv.
------------------------------------------

I hope this helps.

Bob
____________________________________________________
See my books and essays at:
http://members.bellatlantic.net/~vze3cxxp/zimbib.htm