Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

Thanks.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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'...

share|improve this answer
    
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. –  Shrikant Sharat Apr 24 '11 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!

share|improve this answer
    
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? –  Shrikant Sharat Mar 28 '11 at 7:03

Your Answer

 
discard

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.