Xclip image binary contents pasted into text fields

clipboardxclip

Say I pick some png file and run the following command:

xclip -selection clip -t image/png image.png

I now have that image in my clipboard. If I paste it somewhere that accepts an image, it is pasted as expected and all is good.

Now instead consider that I press ctrl+V while being in the firefox address bar or in the text field I'm typing this in. The binary contents of the file are pasted verbatim into the text field, in some cases causing the browser to hang for a while.

Of course I know it doesn't make sense to paste an image there, but I sometimes do it accidentally, and then it causes problems.

When I instead paste an image I copied using firefox's "copy image" button, it doesn't get pasted when I try to paste it, so it must be possible to store it in the clipboard to allow for this behaviour.

How can I place an image in the clipboard without making the image get pasted verbatim as binary data into text fields? If it's possible to somehow place both an image and a text string (such as the path to the image or something) in the clipboard and have it pick the appropriate one when pasting, that would be awesome.

Best Answer

I copied an image into clipboard with xclip like you did and here's what list of targets I got:

> xclip -selection clip -t TARGETS -o
TARGETS
image/png

and now if I copy an image from a web page I get this:

> xclip -selection clip -t TARGETS -o
TIMESTAMP
TARGETS
MULTIPLE
SAVE_TARGETS
text/html
text/_moz_htmlinfo
text/_moz_htmlcontext
image/png
image/jpeg
image/x-icon
image/x-ico
image/x-win-bitmap
image/vnd.microsoft.icon
application/ico
image/ico
image/icon
text/ico
image/tiff
image/bmp
image/x-bmp
image/x-MS-bmp

and for example setting target as text/html gives such output

> xclip -sel c -t text/html -o       
<img src="..." alt="...">>

So obviously it's xclip problem as stated in prev answer

Related Question