maim icon indicating copy to clipboard operation
maim copied to clipboard

Can't pipe maim into xclip if I specify a name to create a file

Open The-Sound opened this issue 6 months ago • 2 comments

Hi there! For the past week or so, I started piping maim into xclp as per the examples, which I completely forgot I was able to. The command I'm using, resides in the i3 configuration files of a Void installation, and goes like this, in case context is necesary (path is absolute, just redacted):

bindsym --release Print exec --no-startup-id maim -b 1 -s -m 1 -p 5 -u Clipboard.png | xclip -selection clipboard -t image/png

My intention with the command was to pipe it, but to create a file too in case I need it.

I've found I can reproduce the issue from terminal too. It will not spite any error, but when I try to paste from any clipboard, a blank image will follow, or nothing at all depending on the program pasted in: Image

When hovering on some past issues, I've found that someone checked the image being pipe, so I did:

maim -b 1 -s -m 1 -p 5 -u Clipboard.png | file -
/dev/stdin: empty

Kinda weird because past week was working, so somehow wondered if somehow creating the file was stopping it from being piped, and voila:

maim -b 1 -s -m 1 -p 5 -u | file -
/dev/stdin: PNG image data, 349 x 112, 8-bit/color RGBA, non-interlaced

I was wondering if this is actual expected behaviour, and/or if I could have it the way I wanted with a file AND a image in the clipboard. I couldn't find any example to do this so apologies if there's one and I've missed it.

The-Sound avatar May 11 '25 01:05 The-Sound

This is expected behavior as maim is designed to only have one output.

It's annoying but the intended functionality is to write out a file and then read out the same file to clipboard again.

It would be nice if it threw an error or simply wrote out the byte stream twice so there was less confusion though.

naelstrof avatar May 11 '25 10:05 naelstrof

I see. Is there anything I can do to keep using a one liner to get both behaviours or am I stuck with making a script with 2 commands?

EDIT: I think I've found a solution, I've tested a little bit around with tee and as I was getting the same result as above:

maim -b 1 -s -m 1 -p 5 -u | tee Clipboard.png | file -
/dev/stdin: PNG image data, 291 x 170, 8-bit/color RGBA, non-interlaced

I've tried to put xclip on the other side and works perfectly for now. I'm not sure if this is gonna have any wrong behaviour but if it is alright for you, we could close this. I don't know if it is worth adding it to the examples, if you like to.

The-Sound avatar May 11 '25 10:05 The-Sound