You are not logged in.

#1 2021-07-14 18:24:37

zeroxoneafour
Member
Registered: 2021-03-20
Posts: 25

xclip - no image/png MIME type

I'm using xclip, shotgun, and hacksaw as a screenshot tool. This is the script I have, attached to the keyboard print key -

selection=$(hacksaw); shotgun -g $selection - | xclip -t image/png -selection clipboard

But xclip copies the image as text, making it unusable. I confirmed this by running xclip -o -t TARGETS right after copying, and I got this -

TIMESTAMP
TARGETS
MULTIPLE
UTF8_STRING
COMPOUND_TEXT
TEXT
STRING
text/plain;charset=utf-8
text/plain

As you can see, there is no image/png MIME type, despite me explicitly stating the copied image as having that type. I would like the image to be copied as an image/png.
The Arch Linux system has been freshly (re)installed, but it didn't work before either. The reinstall was irrelevant to this issue.

Offline

#2 2021-07-15 10:21:13

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,866

Re: xclip - no image/png MIME type

I guess you're trying the hacksaw example from shotgun readme ?

The example has single quotes around image/png , if you add those do the results differ ?

Another possibility is differences between archlinux xclip and NixOS xclip . You could try asking upstream if they tested that example on archlinux .


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

#3 2021-07-15 11:44:06

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,433

Re: xclip - no image/png MIME type

I have similar script using maim and xclip, and it works ( image remains image )

maim -u -s | xclip -selection clipboard -t image/png

EDIT: I installed shotgun  to check this and it works as well, here is my script

#!/bin/bash

FILE=/tmp/image.png
COUNT=1
while [ -f $FILE ]; do
    FILE=/tmp/image$COUNT.png
    COUNT=$(( $COUNT + 1 ))
done

#maim -u -s | xclip -selection clipboard -t image/png

sel=$(slop -f "-i %i -g %g")
shotgun $sel - | xclip -selection clipboard -t image/png
xclip -selection clipboard -o > $FILE
notify-send -u normal "Image copied to clipboard and $FILE"

This script copies image to clipboard as well as to a file in /tmp folder.
I don't get image/png, in "xclip -o -t TARGETS" as well.

Last edited by Docbroke (2021-07-15 12:38:37)

Offline

#4 2021-07-15 16:34:47

zeroxoneafour
Member
Registered: 2021-03-20
Posts: 25

Re: xclip - no image/png MIME type

Lone_Wolf wrote:

I guess you're trying the hacksaw example from shotgun readme ?

The example has single quotes around image/png , if you add those do the results differ ?

Another possibility is differences between archlinux xclip and NixOS xclip . You could try asking upstream if they tested that example on archlinux .

I have tried them both, neither work

Offline

#5 2021-07-16 11:46:34

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,866

Re: xclip - no image/png MIME type

I decided to test the example from upstream and it does work.

after running the script I opened libreoffice writer and pasted clipboard contents to it and got the screenshot I took as image .

Are you using bash or another shell,  zeroxoneafour ?


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

#6 2021-07-16 19:58:51

zeroxoneafour
Member
Registered: 2021-03-20
Posts: 25

Re: xclip - no image/png MIME type

I'm using bash, but I bound it to the print key via sxhkd. It would appear some applications can detect the image as an image, whereas others detect it as text. I guess the prompt that you paste it into matters. It seemed to work better after I got the xclip-git package from the AUR/

Offline

#7 2021-07-16 20:40:26

progandy
Member
Registered: 2012-05-17
Posts: 5,184

Re: xclip - no image/png MIME type

I don't get image/png, in "xclip -o -t TARGETS" as well.

You need to always set the correct selection, xclip works fine here (xclip 0.13-3)

$ xclip -selection clipboard -i -t image/png <prawn.png
$ xclip -selection clipboard -o -t TARGETS
TARGETS
image/png
$ xclip -selection clipboard -o -t image/png | display -

I can also image that some applications fail when TIMESTAMP is not set, maybe they only work with MULTIPLE selections which would be bad design, or require at least two formats because they are buggy. (timestamp and multiple are defined in ICCCM)

If the git version works better, then it may also be the result of this I think: https://github.com/astrand/xclip/pull/57
By the way, if you use the git version you really need this pull-request or you may get segfaults: https://github.com/astrand/xclip/pull/121

Last edited by progandy (2021-07-16 21:11:37)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

Board footer

Powered by FluxBB