2

When I have binary content on my clipboard, I want to dump it into a file. For example, on an internet browser I could right click on an image and click "Copy Image", the image data will be then, copied to my clipboard, which I can easily paste on image editing softwares. Now I want to dump the image into a file:

So from this question: How to pipe/dump clipboard contents to a file?

I tried these:

xsel -b > Picture.jpg

xclip -selection clipboard -o > Picture.jpg

gpaste-client get 0 > Picture.jpg

But the file always contains 0 bytes.

When I pipe these commands to od and xxd or cat I just get 0000000 or nothing at all.

When the clipboard contains a string, these commands ALL work fine, but when it's binary, nothing works!

1

1 Answer 1

0

In the 30+ years that I have been working with X11, I never saw this working well in any environment. Even copying and pasting plain text with the X clipboard vs. what all the different desktops (KDE, Xfce, GNOME) do is hit and miss.

Do yourself the favour and use good old "save image as..." in your browser. You'll save yourself a ton of headaches.

Background: Both the clipboard source application and the target application would need to have a common idea how to interpret the clipboard content. Is it a PBM? A PNG? A JPG? Any of the other several dozen image formats? Or is it some video format? And which one?

The only thing that works quite well is drag'n'drop between several desktop applications of the same kind, i.e. from one PcManFM window to another PcManFM window or to a Gimp window. Or from one Dolphin window to another Dolphin window; you get the idea. With a little bit of luck, it MIGHT work from some KDE filemanager window to, say, a GNOME image viewer window. But I wouldn't bet on that.

And even then you are really dragging and dropping the path of that file, not the pixels; the target application sees the path and opens that file. Very simplistic.

3
  • But my purpose is to first pipe the content to imagemagick, convert the image using STDIN like this: convert - -trim jpg:- and at the end with the result of conversion, I might dump it to a file or even pipe it to clipboard again.
    – Shayan
    May 28, 2021 at 20:22
  • But I see where you're coming from. If there's really no way, not even a slight hope then I'll give up.
    – Shayan
    May 28, 2021 at 20:22
  • Use "save as..." a lot, and when you collected a bunch of them, go to that directory and use mogrify to convert them all at the same time.
    – HuHa
    May 28, 2021 at 20:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .