Copy Path in Nautilus
I recently switched to Ubuntu. Starting to like it.
Here is my first Ubuntu/Nautilus hack. Put the following python script:
#!/usr/bin/python
import pygtk
pygtk.require('2.0')
import gtk
import os
# get the clipboard
clipboard = gtk.clipboard_get()
# set the clipboard text data
clipboard.set_text(os.environ['NAUTILUS_SCRIPT_SELECTED_FILE_PATHS'])
# make our data available to other applications
clipboard.store()
in the file:
~/.gnome2/nautilus-scripts/Copy Path
Now launch Nautilus, select any file(s) or folder(s) and invoke pop up menu and select Scripts:Copy Path. The fully qualified path(s) of the file(s) or folder(s) will be copied to the clipboard.
Does anyone know a better way?
Posted by sandipchitale
( Aug 25 2007, 12:15:00 PM PDT ) Permalink
Trackback URL: http://blogs.sun.com/scblog/entry/copy_path_in_nautilus
Using bash and xclip:
#!/bin/bash
#
echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"|/usr/X11R6/bin/xclip -selection "clipboard"
Found here:
http://ubuntuforums.org/showthread.php?t=104410
Copy to Clipboard and Open Command Window Here are built into Vista's Right-Click menu if you hold down SHIFT [1]. Hopefully, Nautilus will catch up to Vista and have this essential functionality built-in as well. Distros can at least include nautilus-open-terminal by default. I use Fedora.
[1] http://shellrevealed.com/forums/thread/841.aspx
Posted by Allen Halsey on September 16, 2008 at 02:51 PM PDT #
I had tried the bash xclip solution first which didn't work quite right (path was stored in the clipboard but only through Ctrl-V, the paste option didn't come up in the right-click menu).
So I tried your python script and that worked perfectly. Thanks! I'd been wanting to get this right for quite some time but it never seemed worth reading gtk docs just for that.
Posted by Tim on September 25, 2008 at 01:50 PM PDT #
This was what I needed.
Thanks !!!
I've improved the code, to suit my needs, in order to chop the newline at the end using rstrip: os.environ['NAUTILUS_SCRIPT_SELECTED_FILE_PATHS'].rstrip('\n')
Posted by Walter Cattebeke on February 01, 2009 at 04:58 PM PST #