Search This Blog

Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Saturday, June 22, 2024

Save image from clipboard using xclip in cli

xclip -selection clipboard -t image/png -o > image.png

[options]

1) -selection

specify which X selection to use, options are "primary" to use XA_PRIMARY (default), "secondary" for XA_SECONDARY or "clipboard" for XA_CLIPBOARD 

Note: -se can be used as short form of selection

From man page: Options can be abbreviated as long as they remain unambiguous. For example, it is possible to use -d or -disp instead of -display. However, -v couldn't be used because it is ambiguous (it could be short for -verbose or -version), so it would be interpreted as a filename.

Since -s can be -selection or -silent hence minimum -se is required.


2) -t, -target

specify a particular data format using the given target atom.  With -o the special target atom name "TARGETS" can be used to get a list of valid target atoms for this selection. 

List available targets for available copy: xclip -sel clipboard -t TARGETS -o

Sample Output:

image/png
image/bmp
image/cur
image/ico
image/jpeg
image/jpg
image/pbm
BITMAP
image/pgm
image/ppm
PIXMAP
image/xbm
image/xpm
TARGETS
MULTIPLE
TIMESTAMP
SAVE_TARGETS

3. -o, -out

print the selection to standard out (generally for piping to a file or program)