1

I want to be able to select a file, enter a command and have it return the current location of the file selected in a terminal.

7
  • unclear. Be specific. How did you open that file? Jun 2, 2014 at 16:14
  • I have just clicked on it in nautilus, it has the orange selection, I haven't opened it.
    – Tim
    Jun 2, 2014 at 16:20
  • What is the use case? Are you trying to automate something, or is it just a convenience?
    – l0b0
    Jun 2, 2014 at 16:26
  • It is to copy the file to a shared folder when I drag it to the side of the screen.
    – Tim
    Jun 2, 2014 at 16:27
  • @Tim, What's the deference, adding that shared folder to bookmakes on side panel. It seems same, you just need to drag it (with Ctrl key pressed for copying)
    – user.dz
    Jun 2, 2014 at 16:43

2 Answers 2

0

If you want to get a file name into a terminal program, you should be able to use either mouse drag'n'drop or Ctrl-c and Ctrl-(Shift-)v to copy/paste it into an editor/terminal.

1
  • Is there a way without dragging it to the terminal, just having it selected, then executing a command to display the location there?
    – Tim
    Jun 2, 2014 at 16:19
0

I think the best thing to fit here is a nautilus plugin.

  1. Install python-nautilus

    sudo apt-get install python-nautilus
    
  2. Create a plugin "TestExtension.py"

    sudo nano /usr/share/nautilus-python/extensions/TestExtension.py
    

    This extension will call your script whenever the selection changes and pass the selection one by one as second command argument $1:

    from gi.repository import Nautilus, GObject
    import os
    
    class ColumnExtension(GObject.GObject, Nautilus.MenuProvider):
        def __init__(self):
            pass
    
        def menu_activate_cb(self, menu, file):
            print "menu_activate_cb",file
    
        def get_file_items(self, window, files):
    
            for file in files:
                uri = file.get_uri()
                if uri.startswith("file:///"):
                    os.system("yourscript_path"+" \""+uri[7:]+"\"")
    
            return
    

    Or you may make a list, combine them as single string, then export it as env variable. So current selection will be accessible for all other scripts. (security hole)

  3. Kill nautilus

    pkill nautilus
    

Reference:

You must log in to answer this question.

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