Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to set the clipboard to file abc.jpg, in image format, so I can paste it to gpaint, etc. X11 applications, can I?

I have enabled Screen snapshot feature in Compiz windows manager, and I need to give a command line to copy the snapshot image file to the clipboard.

share|improve this question

First, install python, and pygtk

sudo apt-get install python pygtk

Now save the following script somewhere as (see

#! /usr/bin/python

import pygtk
import gtk
import os
import sys

def copy_image(f):
    assert os.path.exists(f), "file does not exist"
    image = gtk.gdk.pixbuf_new_from_file(f)

    clipboard = gtk.clipboard_get()


To use it:

python /path/to/ filename.png

Note: tested pasting in gimp and xournal. Note: this is for gnome desktop (hence gtk). I bet there's something similar for kde

share|improve this answer

Check out xclip. It allows you to move text, or files to the clipboard from the command line.


There are command-line screenshot apps discussed in this post: including scrot. This is from the scrot man page:

scrot  is  a  screen capture utility using the imlib2 library to aquire
       and save images.  scrot has a  few  options,  detailed  below.  Specify
       [file]  as  the  filename  to save the screenshot to.

One last option is to find an X app which just takes a screenshot when clicked (no prompts, dialogue boxes etc), assign it to a hotkey combination and use xdotool to simulate that keypress from the command line??

share|improve this answer
@OP, did you actually need a command line tool, or are you just trying to get a screenshot into the clipboard? There's much easier way to go that – Jeremy Oct 14 '10 at 4:17
Yes, I need a command line tool. – Xiè Jìléi Oct 15 '10 at 1:19
Unfortunately, both xclip and xsel don't work with images, they work with text contents only. – Xiè Jìléi Oct 15 '10 at 1:20
Right, my bad, I didn't try pasting into a graphics program, I only tried xclip < image.jpg and xclip -o > image2.jpg which works, but is useless ;( – Jeremy Oct 16 '10 at 11:56
I tested scrot, it works nicely to get a screenshot straight out to a file, but it can't get it into the clipboard :/ – Jeremy Oct 16 '10 at 12:10

I'd disable Compiz's screenshot feature, just Head over to System -> Preferences -> Keyboard Shortcuts (under Desktop category) and bind Print Screen to Take a Screenshot

enter image description here

Now whenever you hit PrintScreen a sreencapture will be taken with an option to copy to clipboard, or just to save the file.

enter image description here

share|improve this answer
No, I like the screen shot feature comes from Compiz. – Xiè Jìléi Oct 15 '10 at 1:07
A small question, how do you make the "Print Screen" button in SU? – Xiè Jìléi Oct 15 '10 at 1:22
@谢继雷 oh just put the the desired button between <kbd> & </kbd> – Sathya Oct 15 '10 at 2:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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