mob-i-l
Posts: 256
Joined: Sat Dec 29, 2012 2:45 am
Location: Lund, Skåne/Scania, Sweden
Contact: Website Facebook Google+ Twitter YouTube

How to copy from a browser into e.g. a terminal?

Thu Oct 03, 2013 11:27 am

I wanted to copy some bash code from a forum into the terminal when I run X in the latest Rasbian from Raspberry Pi. I tested all three browsers and even installed links and run that in another terminal tab, but I was either not able to select text using the mouse or when I used Ctrl+C or Copy from a menu nothing happened. I can copy and paste the URL/location but not any text from the browser window. I can copy from Leafpad and into the terminal. I can copy from the terminal and into Leafpad but not when I'm running Links.

At last I had to use wget to download the entire forum page and then open the text file in Leafpad and the edit out the relevent code and remove syntax coloration HTML and CSS. I was lucky that I could use Wget this time because that is not possible if the text is generated in the browser using JavaScript.

Should it be this difficult to do a common everyday task in Rasbian? Is there no better way to copy from a browser into another program running in X?
Have Pi0&1A&1B&1B+&2B&3B&4B w/ Raspbian. Started w/ BASIC on ABC80&ZX81 then Forth, Z80… https://scratch.mit.edu/users/mobluse/ https://github.com/mobluse/ https://twitter.com/mobluse/ https://YouTube.com/MOBiL4u/

confuseling
Posts: 144
Joined: Mon Aug 26, 2013 1:41 pm

Re: How to copy from a browser into e.g. a terminal?

Thu Oct 03, 2013 11:45 am

I don't find it hard, which probably just means it's unfamiliar.

Few points to consider:

In Linux, many things are interchangeable and configurable, and many people prefer using a visible program to manage their clipboard. I've used Klipper before with some success, Parcelite has always been popular too.

http://packages.debian.org/wheezy/klipper

It's often easiest to use the middle mouse paste buffer - select the text to 'copy' it, middle click to paste. Most people find this weird at first, but get used to it.

Finally, it could be a quirk / setting of the terminal emulator. You tried any others? I like Konsole, but it can be a little slow. I know Urxvt is popular with tiling window manager users, which probably makes it quick.
http://forums.debian.net

User avatar
mad-hatter
Posts: 419
Joined: Sun Feb 26, 2012 2:58 pm
Location: By the UK seaside

Re: How to copy from a browser into e.g. a terminal?

Thu Oct 03, 2013 11:58 am

Hello,

Highlight the text in the browser, right click on the highlighted text and select copy.
Open a terminal or leafpad, right click in the area and select paste.
Works for me in 'Raspian'.

Regards

User avatar
joan
Posts: 14093
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: How to copy from a browser into e.g. a terminal?

Thu Oct 03, 2013 12:05 pm

The standard way is select text and then ctrl c to copy. ctrl v will normally paste.

Terminal windows are different. You need to use shift ctrl C to copy and shift ctrl V to paste.

User avatar
jojopi
Posts: 3078
Joined: Tue Oct 11, 2011 8:38 pm

Re: How to copy from a browser into e.g. a terminal?

Thu Oct 03, 2013 12:08 pm

There are two main methods of copy and paste in X11:

1) Select some text by double clicking and/or dragging the mouse pointer.
Paste the text into another window by clicking the middle button (or scroll wheel).

2) Select some text. Copy the text to the clipboard by right click →Copy, or Edit→Copy from the menu, or Shift+Delete, or Ctrl+C.
Paste the text into another window by right click→Paste, or Edit→Paste from the menu, or Shift+Insert, or Ctrl+V.
In a terminal, Ctrl+C/V already have more important uses, but you may be able to use Shift+Ctrl+C/V.

It should be clear that method 1 (PRIMARY selection) is superior to method 2 (CLIPBOARD selection). One benefit of the clipboard is that it can hold a longer-term selection, without being disturbed by intervening primaries.

You do not need to run an actual clipboard program, unless you require it for format conversion, or to keep a selection alive after the original client application has exited.

confuseling
Posts: 144
Joined: Mon Aug 26, 2013 1:41 pm

Re: How to copy from a browser into e.g. a terminal?

Thu Oct 03, 2013 12:09 pm

Ctrl - Insert / Shift - Insert also works in my setup, but I don't know whether that's standard X, or something else entirely.
http://forums.debian.net

mob-i-l
Posts: 256
Joined: Sat Dec 29, 2012 2:45 am
Location: Lund, Skåne/Scania, Sweden
Contact: Website Facebook Google+ Twitter YouTube

Re: How to copy from a browser into e.g. a terminal?

Thu Oct 03, 2013 1:13 pm

Copying from a browser to a terminal is a common everyday task and that should be possible to do with a distribution out of the box. Especially since Rasbian is the recommended distribution for a beginners computer like Raspberry Pi it should be easy to use out of the box.

What I wanted to copy was the bash code in this forum post (this is one long command-line):
http://scratch.mit.edu/discuss/topic/15 ... ost-153265

Using select and the middle mouse button doesn't work since it is not always possible to select or the browsers in Rasbian doesn't support this way of copying this particular text. Other ways of copying also didn't work. It is possible to copy other texts on this page but this bash code is in a code box. But most code snippets in forums are in code boxes so a browser must be able to handle them. Also I don't have a middle mouse-button since I have a keyboard with a small joystick and only two buttons. I know you can simulate a middle mouse-click by pressing both buttons at exactly the same time but this is difficult to do since the buttons are hard to press. But even when I succeeded pressing them at once nothing was pasted.

I guess the main problem is that none of the standard browsers in Rasbian handle code boxes in DjangoBB with very long text on a single line in a correct way.

If anyone could come up with a solution of how to copy this particular bash command-line on the Scratch forum to the terminal using only one of the default graphical browsers in Rasbian I would consider recommending Rasbian and Rasberry Pi. Note that Scratch is also a default system in Rasbian and then one should of course be able to use its forum in an easy way and be able to copy long Bash command-lines in code boxes into the default terminal in Rasbian.
Last edited by mob-i-l on Thu Oct 03, 2013 1:47 pm, edited 1 time in total.
Have Pi0&1A&1B&1B+&2B&3B&4B w/ Raspbian. Started w/ BASIC on ABC80&ZX81 then Forth, Z80… https://scratch.mit.edu/users/mobluse/ https://github.com/mobluse/ https://twitter.com/mobluse/ https://YouTube.com/MOBiL4u/

User avatar
joan
Posts: 14093
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: How to copy from a browser into e.g. a terminal?

Thu Oct 03, 2013 1:28 pm

No, that is impossible.

Code: Select all

proj=12612306; mkdir sb2tmp; cd sb2tmp; curl -L http://scratch.mit.edu/internalapi/project/$proj/get/ 2> /dev/null | tee project.json | grep -i MD5 | cut -d' ' -f2 | sed 's/[\",]//g' | while read file; do curl -L -o $file http://scratch.mit.edu/internalapi/asset/$file/get 2> /dev/null; done; i=1; while [ $i -le `expr $( ls -1 | wc -l ) - 2` ]; do sed -i "{s/ID\": -1/ID\": $i/;t end;b;:end;n;b end}" project.json; i=`expr $i + 1`; done; i=0; ( grep penLayerMD5 project.json; grep '\(baseLayerMD5\|md5\)' project.json ) | cut -d' ' -f2 | sed 's/[",]//g' | while read file; do ext=`echo $file | cut -d. -f2`; mv $file $i.$ext; i=`expr $i + 1`; done; zip $proj.sb2 *; mv *.sb2 ..; cd ..; rm -r sb2tmp

User avatar
jojopi
Posts: 3078
Joined: Tue Oct 11, 2011 8:38 pm

Re: How to copy from a browser into e.g. a terminal?

Thu Oct 03, 2013 8:43 pm

mob-i-l wrote:It is possible to copy other texts on this page but this bash code is in a code box.

I guess the main problem is that none of the standard browsers in Rasbian handle code boxes in DjangoBB with very long text on a single line in a correct way.
If anything, being on one line and in a code box makes selection easier. You can triple-click anywhere in the box instead of carefully lining up the beginning and end of a mouse drag. All of the other usual methods work too, though, at least in the default midori and lxterminal, and almost certainly in all the browsers and terminals.

It seems that you are not a beginner, as we may have previously assumed, but have used Linux on other platforms. I am struggling to think what you might be doing differently that could lead to your incorrect conclusion that this simple operation is not possible in Raspbian.

Have you checked that your keyboard/mouse is working reliably and producing the correct events when tested with "xev"? Can you tell whether the problem is with the selection/copy part of the operation, or with the paste? Exactly what programs and methods are you trying, and where does the behaviour differ from what would be expected?

tvjon
Posts: 708
Joined: Mon Jan 07, 2013 9:11 am

Re: How to copy from a browser into e.g. a terminal?

Fri Oct 04, 2013 12:08 pm

mob-i-l wrote:......

What I wanted to copy was the bash code in this forum post (this is one long command-line):
http://scratch.mit.edu/discuss/topic/15 ... ost-153265

Using select and the middle mouse button
........
I've just opened "luakit", my favourite browser for RPi (unlike you, I'm a Linux novice), double clicked your link, selected all that code block, then back to my open terminal window, pressed middle button (incorporated in the scroll wheel) & all of that code has appeared thusly:

[email protected] ~ $ proj=12612306; mkdir sb2tmp; cd sb2tmp; curl -L http://scratch.mit.edu/internalapi/project/$proj/get/ 2> /dev/null | tee project.json | grep -i MD5 | cut -d' ' -f2 | sed 's/[\",]//g' | while read file; do curl -L -o $file http://scratch.mit.edu/internalapi/asset/$file/get 2> /dev/null; done; i=1; while [ $i -le `expr $( ls -1 | wc -l ) - 2` ]; do sed -i "{s/ID\": -1/ID\": $i/;t end;b;:end;n;b end}" project.json; i=`expr $i + 1`; done; i=0; ( grep penLayerMD5 project.json; grep '\(baseLayerMD5\|md5\)' project.json ) | cut -d' ' -f2 | sed 's/[",]//g' | while read file; do ext=`echo $file | cut -d. -f2`; mv $file $i.$ext; i=`expr $i + 1`; done; zip $proj.sb2 *; mv *.sb2 ..; cd ..; rm -r sb2tmp
adding: 0.png (deflated 89%)
adding: 1.png (deflated 93%)
adding: 2.wav (deflated 12%)
adding: 3.wav (stored 0%)
adding: 4.png (deflated 1%)
adding: 5.png (deflated 4%)
adding: project.json (deflated 82%)
[email protected] ~

Next I pressed carriage return & you can see the result.

I'm very surprised you can't get that to work. Luakit uses WebKit, like many other browsers.

All the above is posted via luakit from a RPi running Raspbian.

mob-i-l
Posts: 256
Joined: Sat Dec 29, 2012 2:45 am
Location: Lund, Skåne/Scania, Sweden
Contact: Website Facebook Google+ Twitter YouTube

Re: How to copy from a browser into e.g. a terminal?

Fri Oct 04, 2013 9:39 pm

I did only use the built-in browsers and I don't have a mouse wheel. As I wrote above, to my Raspberry Pi I have a keyboard with a small joystick and two mouse-buttons. I've tried to use mark in LXTerminal and paste by clicking simultaneously (this should simulate middle-click), but then the terminal closes (the mouse-pointer was in about the middle of the terminal window). I've used Linux (Slackware) and X since 1996 (and I read a book about X then) and have never experienced this, but there have been difficulties of copying and pasting between programs before. I now normally use Ubuntu 10.04 LTS and 12.04 LTS. I have been able to copy from Midori to LXTerminal but not from this particular code-box with a long line on the Scratch-forum. If this browser you mention is so good maybe it should be default.
Have Pi0&1A&1B&1B+&2B&3B&4B w/ Raspbian. Started w/ BASIC on ABC80&ZX81 then Forth, Z80… https://scratch.mit.edu/users/mobluse/ https://github.com/mobluse/ https://twitter.com/mobluse/ https://YouTube.com/MOBiL4u/

sdjf
Posts: 1395
Joined: Fri Mar 16, 2012 5:20 am
Location: California
Contact: Website

Re: How to copy from a browser into e.g. a terminal?

Sun Feb 09, 2014 3:29 pm

Try installing autocutsel. I was having trouble with copy/paste between various applications, and using that has solved all my problems. Although I am running Arch and not raspbian, I think it is a lightweight daemon worth installing. It synchronizes clipboard buffers. In Arch, pacman gave the code for getting autocutsel to run properly, I would hope that it will be in raspbian's install instructions or info pages as well.

And, I have no mouse, everything I am doing is using mouse emulation tools in openbox, right now, xdotool emulates clicks, mousedown and mouseup events. My only challenge is learning when to enter what mouse emulation to effect a copy.

I am not using graphical browsers on Pi, but do copy/paste from firefox over vnc to my Pi. Sometimes I have to do a double left click, move the mouse pointer to end of selection, then do, one after the other, mousedown and then mouseup. In other cases, the mousedown must preceed the mousemove events, followed by mouseup and ctrl-c. It varies with application, but once I got autocutsel running, my copy/paste troubles disappeared.

For those using text browsers, the one problem with copy/paste is that line ends are inserted at the end of every visual line, regardless of whether it should be one long line of code.

links browser will not allow copy, lynx browser does, and in lynx, a better way to retrieve code is to us the \ to view source, and then copy/paste from the source of the page as lynx inserts a plus sign + at the start of every line that was wrapped, and those are easy to remove with a text editor.
FORUM TIP: To view someone's posting history, sign in, click on their user name, then on "Search User's Posts." || Running ArchLinuxArm on Model 2B and 512MB Model B

spex357
Posts: 29
Joined: Fri Jan 10, 2014 5:15 pm

Re: How to copy from a browser into e.g. a terminal?

Thu Jun 04, 2015 11:49 am

I've never had copy paste to work from a browser in Win7 RDC into Raspian Lxterminal, tried the mouse and all the keyboard shortcuts, start stop rdpclip etc. I was hoping it would work on pi2 but no joy so far.

klricks
Posts: 6508
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: How to copy from a browser into e.g. a terminal?

Sat Jun 06, 2015 1:34 pm

spex357 wrote:I've never had copy paste to work from a browser in Win7 RDC into Raspian Lxterminal, tried the mouse and all the keyboard shortcuts, start stop rdpclip etc. I was hoping it would work on pi2 but no joy so far.
Yes it is really annoying that copy / paste does not work in RDP. Do a Google search and you will find that there is trouble even when remote connection of Windows to Windows machines.

However copy and paste does work in both directions when connected to the RPi remotely with SSH using PuTTY from Windows.
- From Windows to RPi --- Select text and CTRL-C then on RPi use mouse right click to paste text at cursor location.
- From RPi to Windows --- Left click-hold and drag to highlight text then on Windows CTRL-V.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

User avatar
r3d4
Posts: 967
Joined: Sat Jul 30, 2011 8:21 am
Location: ./

Re: How to copy from a browser into e.g. a terminal?

Sun Jun 07, 2015 1:54 pm

mob-i-l wrote: At last I had to use wget to download the entire forum page and then open the text file in Leafpad and the edit out the relevent code and remove syntax coloration HTML and CSS. I was lucky that I could use Wget this time because that is not possible if the text is generated in the browser using JavaScript.
Just FYI..
If you ever have to deal wiith the case that 'the text is generated in the browser using JavaScript'
you can use phantomJS to get the page as you would see it in a browser! =]

User avatar
paulwratt
Posts: 83
Joined: Fri Jun 12, 2015 12:15 am

Re: How to copy from a browser into e.g. a terminal?

Wed Nov 29, 2017 10:32 am

a bit old but FYI non-the-less:

I (mostly) dont use X-Windows, but I do use Chromium Browser and the VT consoles (Ctrl+Alt+Fn). Chrome requires an X DISPLAY to run on. The following are the scripts I use to transfer "selected text" between Chrome (X Windows) and the Linux Console virtual terminals (VT#)

X-copy.sh

Code: Select all

#!/bin/sh
if [ "$1" = "" ]; then
  echo "$0 [display|0] \"value\""
else
A=0
if [ ! "$2" = "" ]; then
  A=$1
  shift
fi
printf "[email protected]" | xsel --display :$A -p -i
printf "[email protected]" | xsel --display :$A -s -i
printf "[email protected]" | xsel --display :$A -b -i
fi
X-paste.sh

Code: Select all

#!/bin/sh
A=0
if [ ! "$1" = "" ]; then
  A=$1
fi
xsel -o --display :$A
NOTES:
see the three (3) different select buffers in X-copy.sh. One is the Ctrl+C/Ctrl+V (Chromium/GTK) (-b) buffer, one is the Ctrl-Insert/Sh-Insert (xterm) (primary) buffer , and I forget the other one (secondary).

Also note that, on X-Windows you can move (copy) selections between buffers without any extra programs, by using a LX-terminal window to switch between the "selection" methods. IE mouse select in xterm, Shift+Insert in LX-terminal, mouse select text in LX-terminal, right-click (or menu) copy. Selected text in Chrome will also Shift+Insert into LX-Terminal as well as right-click (or menu) paste. Selecting text with the mouse in LX-terminal puts it in the buffer xterm can use (-p), right-click (or menu) will put it on the GTK buffer (-b)

Regarding OP:
You can not select user text (textarea or textbox) running "links -g". You can select html page text running "links -g". The docs say there are keys, but only for OS/2. Because "links -g" uses GPM on Linux Console, I believe it is simply a lack of code that does not allow user text to be selected (there is no caret for it, AND it is in a seperate buffer). You can select any text in in "links" or "lynx" terminal or VT console. "eLinks" is un-tested atm.

Hope that helps someone

Paul

Return to “Raspbian”