0

I'm trying to use sxiv to pick an image and pipe that image to the clipboard.

I'm currently using this command:

cat "$(sxiv -foqrt ~/Pictures 2>/dev/null | sed 1q)" | xclip -selection clipboard -t image/png

However, this would only work if the chosen file is a png. It doesn't work with just -t image on xclip. I have multiple file types I want to copy.

How can I get pass the file type problem?

1
  • In my tests there is no problem with passing arbitrary (e.g. random) data to xclip. There is also no problem with retrieving the same data via xclip -o. If the problem occurs when you try to retrieve data and use it with another program then please edit the question and name the program. For now the question suggests the problem is with xclip, I doubt it. Is there any error message form xclip or the other program? What message? Feb 22, 2021 at 17:29

1 Answer 1

0

Since I don't have enough rep to make a comment - you can get the MIME type of the image using file, store it in a temp variable, and then pass that to xclip, like so:

filename="$(sxiv -foqrt ~/Pictures 2>/dev/null | sed 1q)"
filetype="$(file --brief --mime-type "${filename}")"
cat "${filename}" | xclip -selection clipboard -t "${filetype}"

Of course, if you want just image files, then you can wrap the last command in a simple if statement to check whether filetype contains the substring image.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.