I have a collection of small text files that I often want to copy wholesale into, say emails or the like. Ideally I'd like to add an option to the right click menu for these small text files that copies the whole contents of the file to clipboard ready to be pasted.

Or is there some smarter gadget that could manage these snippets? It has to be something that can paste the text into arbitrary texboxes: in firefox, in thunderbird, in emacs...

Is there such a tool?

  • I never thought about the usefulness of such a script. Guess I have to thank you for bringing up the idea. Also thumbs up for your PhD studies. I'm going for a PhD in physics and philosophy of science is an interesting subject.
    – con-f-use
    Aug 4 '11 at 11:14
  • My primary use is for adding one of several different signatures to emails. (I'm sure I could do this in Thunderbird, but it wasn't immediately obvious). It would also be useful for adding stock comments asking for MWEs on SE sites...
    – Seamus
    Aug 4 '11 at 11:18
  • Aslo, good luck with the PhD!
    – Seamus
    Aug 4 '11 at 11:19
  • Thanks. If my answer helped you, maybe you could mark the question answered or upvote the answer...
    – con-f-use
    Aug 4 '11 at 15:08
  • I've not had a chance to try it yet.
    – Seamus
    Aug 4 '11 at 15:27

You could write a small perl script like the one I posted below and run it as a nautilus script.

It would work like this:

  • Mark the files in nautilus
  • Right click for context menu
  • Click 'Scripts' entry of the context menu then click the name of the script (in my case the name is 'contents2clipboard').

Now the contents of all files is in the clipboard an can be pasted into a text editor or any other application.

To use the script copy it into a new file in the ~/.gnome2/nautilus-scripts directory. The file's name will be the text of the corresponding entry in the 'Scripts' menu of nautilus. In my case the name is 'contents2clipboard'.

Here's a screenshot:

contents to clipboard script

Here is the very basic script:

# indent-mode: spaces, tabsize: 4, encoding: utf8
# © 2011 con-f-use@gmx.net. Use under the MIT license:
#     http://www.opensource.org/licenses/mit-license.php
# This nautilus script copies the content of the selected files
#+into the clipboard. Nautlis scripts are usually located in
#+'$HOME/.gnome2/nautilus-scripts' and need to be executable.

# Gtk2 stuff
use Glib qw/TRUE FALSE/;
use Gtk2 '-init';
use utf8;

# Get files list
@files = split( "\n", $ENV{'NAUTILUS_SCRIPT_SELECTED_FILE_PATHS'} );
$content = '';
# read content of files in list
foreach $path (@files) {
    if( -T $path ) {
        open FILE, "<$path";
        $content .= do { local $/; <FILE> };

# Copy content to clipboard
$clipboard = Gtk2::Clipboard->get(Gtk2::Gdk->SELECTION_CLIPBOARD);

As it is it has a few quirks you might want to fix:

  • It doesn't work on remote file systems because of the way NAUTILUS_SCRIPT_SELECTED_FILE_PATHS is handeld.
  • It doesn't check the size of the files provided. So very large files might cause trouble.

Don't know if this suits your needs. If so: enjoy! (and mark answered)


I am using the xfce4-clipman clipboard manager, and it provides exactly what you are asking for. I have it setup such that whenever I copy an url to the clipboard, a small menu appears, and I can choose accordingly.

apt-get install xfce4-clipman xfce4-clipman-plugin

When you have installed the plugin to your panel, find your way to the properties window, where you can configure triggers with regexp. It comes pre-installed with a example that works well for images. And for each regexp trigger, you can edit a list of actions, or commands. In my case, they are typically 'cat' commands, to copy into a selected file, for me to download later.

These actions, or commands become the entries on the small chooser menu that will appear every time you copy something to clipboard that matches the regexp.


I really missed clipboard managers when I switched to Linux years ago. The one in KDE is pretty good, but I have switched to Gnome. I tried Glipper and Parcelite but didn't find they had what I wanted.

I decided to try an write one myself, using Python and pyGTK. It's coming along nicely, and has features I wanted but couldn't find: Snippets, with categories, tags, & icons in history menu. Optional title for a snippet (or clip). Auto appending clipboard contents to a clip. Create a new clip. Load a file into a clip. Save a clip to a file.

A simple plugin architecture allows extra functionality to be added by writing it in Python. I currently have plugins to: delete blank lines. dump snip category to a file. email a clip. explode a clip into several clips. open URL's in a clip in browser. post clip on PasteBin. remove text via a regular expression. remove HTML-XML tags. remove leading characters. remove line numbers. shorten a URL.

Data is kept in a SQLite database, so each clip/snip has properties like date created, last used, times used, title, source & note.

While far from perfect, I find it very useful even at the present stage of development.

  • 1
    Can you give a link to your utility?
    – nanofarad
    Jul 16 '12 at 18:44

I use Clippings Extention for Firefox and QuickText Extention for Thunderbird.



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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