I have a nautilus script that generates an archive file based on the files selected in the nautilus window. This archive file is created in the /tmp directory. I want a way to copy this file to the clipboard from the script, so that the user can just go to desktop or home directory and paste it.

I have tried doing this with xclip and xsel, but they don't seem to replicate a file copying operation, rather they copy the contents of a file.

xclip -in -selection c generated-archive
echo -n generated-archive | xsel --clipboard --input

Neither of them do what I need.

So, I want to know if this is possible, and if it is, how should I go about it?


2 Answers 2


It seems that Nautilus keeps track of it's internal state with respect to changes to the clipboard, which means that any change of state to the clipboard (including replacement with an identical filepath string) automatically cancels the paste pending state, hence nothing happens when an externally loaded clipboard contains a valid filepath...

Nautilus only recognizes a file copy/cut which has been initiated from within Nautilus itself.
This is exactly what you have observed.. with perhap some explanation as to why... I noticed in the Nautilus source 'cut-n-paste-code' that it contains a lot about about saved states.

# In Nautilus, manually "copy" a file (to the clipboard) using Ctrl+C

xsel -ob |xxd      # hex-display clipboard contents of the clipboard
echo "### At this point, Nautilus **paste** works."
read               # pause
xsel -ob |xsel -ib # Replace clipboard with itself
xsel -ob |xxd      # hex-display clipboard contents again
echo "### At this point, Nautilus **paste** does NOT work."

After your manually copy/cut, you can perform endless actions (either in Nautilus or elswhere) and the Ctrl+V paste in Nautilus will work, but as soon as you modify the clipboard, it won't 'paste'...

  • wow! thanks for getting into the source. Your words make a lot of sense, I guess the bottom line is that it can't be done. Oh well. Thanks again.
    – sharat87
    Commented Apr 24, 2011 at 7:12

you should understand that when you 'copy' a file to the clipboard in nautilus, all you're actually doing is putting the absolute filepath on the clipboard (you can use a clipboard manager to verify this). So you simply need to have your script put the filepath on the clipboard, and you will achieve the result you're looking for. Try it!

  • Sorry for getting back so late :). Yes, I have known this and tried this, in fact I tried puting $filepath and file://$filepath in the clipboard, pasting in a text editor works fine, but nautilus is unable to paste the file. And yes, it is the complete file path (/tmp/2034.jar). Any other ideas?
    – sharat87
    Commented Mar 28, 2011 at 7:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .