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?

Comments:

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 07:51 AM 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 06:50 AM 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 08:58 AM PST #

Post a Comment:
Comments are closed for this entry.
About

sandipchitale

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today