Nautilus copy path of directory or file to clipboard (Workaround)

I came here because of Francesco Sensi script to fix the copy buffer on nautilus. It doesn’t work for me. Do you have any idea on what should I do to make it work?

https://www.google.com/url?q=https://gitlab.gnome.org/GNOME/nautilus/issues/634%23note_541313&source=gmail&ust=1566328029985000&usg=AFQjCNER3Ga_gMY2VlvY8LQUd2ohqePQyA

Here is the direct link: https://gitlab.gnome.org/GNOME/nautilus/issues/634#note_541313

I haven’t really looked at that script yet, but in case you’re not aware, you can right click in gnome-terminal and “Paste as Filenames”, or drag-and-drop from nautilus to gnome-terminal.

If you’re using Wayland, the script needs to be run with GDK_BACKEND=x11. Wayland doesn’t let you snoop on the clipboard. Also, it needs to be run with python3, not python (depending on your platform).

I improved it a bit:

#!/usr/bin/python3

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk, Gio
import shlex

def quoted_path(uri):
    path = Gio.File.new_for_uri(uri).get_path()
    if path is not None:
        path = shlex.quote(path)
    return path

def callback(clip, event):
    lines = clip.wait_for_text().strip().split('\n')
    if len(lines) >= 3 and lines[0] == 'x-special/nautilus-clipboard':
        paths = [p for p in (quoted_path(u) for u in lines[2:]) if p is not None]
        clip.set_text(' '.join(paths), -1)

Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD).connect('owner-change', callback)
Gtk.main()

This version supports multiple files, non-file: uris, and filenames with spaces and shell metacharacters.

1 Like

Now we are talking. This is working for me, thanks for the corrections.

@Chrisaw, when the script is running I can’t Ctrl+c, Ctrl+v to copy and paste a file on nautilus anymore. Do you know a fix for that?

This workaround stops working for me. Purism maintains a stable copy Nautilus 3.26 which has everything. I am using it now.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.