How can I make Nautilus file manager remember my open tabs?

orschiro

Is it possible to preserve my open tabs between closing and opening of Nautilus file manager?

Preferably even across different logouts and restarts.

Jacob Vlijm

(Very) limited command line options of nautilus

Unfortunately, nautilus does not offer command line options to read the opened directory of its windows, nor does it have any option to send an existing window to another directory. Since you cannot remember what you do not see, we are running out of options at first sight.

However

We do have xdotool, not to do what nautilus doesn't, but to at least fake the behaviour that you describe. We can do that in such a way that "you would believe it" if you didn't know how it is done.

Although the solution below does not survive a restart, "remembering" (possibly tabbed) window and all opened directories is very well possible within one session. Since you mentioned to be interested in that as a "second choice", here it is.

How it works; the process

Although We cannot close a window and preserve its tabs and opened directories, we can make an existing window seemingly (and completely) disappear, with the help of xdotool.

If we subsequently change the behaviour of the nautilus launcher in such a way that it first looks for possible unmapped windows to remap, before opening a new one, effectively we have exactly the same behaviour as if nautilus would remember the last used window(s).

How to set up

  1. Copy the script below into an empty file, save it as remember.py

    #!/usr/bin/env python3
    import subprocess
    import os
    
    app = "nautilus"
    
    wfile = os.environ["HOME"]+"/.unmapped_"+app
    
    def get(cmd):
        # simply a helper function
        return subprocess.check_output(cmd).decode("utf-8").strip()
    
    def check_windowtype(w_id):
        # check the type of window; only unmap "NORMAL" windows
        return "_NET_WM_WINDOW_TYPE_NORMAL" in get(["xprop", "-id", w_id])
    
    def get_pid(app):
        # (try to) get the pid of the application 
        try:
            return get(["pgrep", app])
        except subprocess.CalledProcessError:
            pass
    
    def get_matches(pid):
        # get the window list, select the valid (real) app's windows
        ws = get(["wmctrl", "-lpG"]).splitlines()
        matches = [w.split() for w in ws if pid in w]
        return [w for w in matches if check_windowtype(w[0]) == True]
    
    try:
        # try to read the file with unmapped windows
        wininf = [l.split() for l in open(wfile).readlines()]
    except FileNotFoundError:
        # if there are no, unmap the current app's windows
        filebrowserwins = get_matches(get_pid(app))
        if filebrowserwins:
            open(wfile, "wt").write(("\n").join((" ").join(l) for l in filebrowserwins))
            for w in [w[0] for w in filebrowserwins]:
                subprocess.Popen(["xdotool", "windowunmap", w])
        else:
            arg = "--new-window" if app == "nautilus" else "" 
            subprocess.Popen([app, arg])
    else:
        # re- map unmapped windows
        for w in wininf:
            wid = w[0]; geo = w[3:7]
            subprocess.call(["xdotool", "windowmap", wid])
            subprocess.Popen(["wmctrl", "-ir", wid, "-e", "0,"+(",").join(geo)])
        os.remove(wfile)
    
  2. The script needs both wmctrl and xdotool:

    sudo apt-get install wmctrl xdotool
    
  3. Copy the nautilus launcher from /usr/share/applications to ~/.local/share/applications

    for 15.04 and later:

    cp /usr/share/applications/org.gnome.Nautilus.desktop ~/.local/share/applications
    

    for earlier Ubuntu versions:

    cp /usr/share/applications/nautilus.desktop  ~/.local/share/applications
    
  4. open the local copy with gedit:

    gedit ~/.local/share/applications/org.gnome.Nautilus.desktop
    

    (in case of 15.04 +)

    and look for the first line, starting with Exec=. Change it into:

    Exec=python3 /path/to/remember.py
    

    Save and close the file.

  5. Create a keyboard shortcut with the same command: Choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:

    python3 /path/to/remember.py
    
  6. Now log out and back in

How to use

The use is very simple:

  • To open a window, do as usual: click on the nautilus launcher. Tab the window as you like:

    enter image description here

  • To close a window definitively, close it by clicking on the window's "close" (x) box.

  • To preserve the window(s) + all its tabs:
    press the shortcut key. The window(s) will vanish (seemingly close).

    enter image description here

  • Next time when you click the launcher, the nautilus window(s) will appear exactly like the last time, even the window position(s) will be preserved.

    enter image description here

That's it

Note

  • In the tests I ran, I couldn't find any downside (14.04). If you might run into any, please mention!
  • In the How to use -section, I suggested to click on the nautilus icon to remap possible unmapped windows. The shortcut key will do the same however, so you can see what works the most convenient for you. Also, if you opened a folder by double click after you unmapped on or more folders, unmapped folders still will be remapped by the shortcut.

EDIT:

Nemo users

Nemo users can equally use the solution above, but:

  • In the head section of the script, change:

    app = "nautilus"
    

    into:

    app = "nemo"
    
  • In point 3, use:

    cp /usr/share/applications/nemo.desktop ~/.local/share/applications
    
  • In point 4, use:

    gedit ~/.local/share/applications/nemo.desktop
    

Tested, proved to be working with nemo

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Nautilus File Manager closes immediately I open it

From Dev

How to make nautilus the default file manager in LXDE

From Dev

How to make nautilus the default file manager in LXDE

From Dev

How can I get the Nautilus file manger to open?

From Dev

How can I open a folder in Atom editor directly from within my file manager's context menu?

From Dev

How to open Ubuntu Gnome 16.04 Nautilus (File Manager) preferences?

From Dev

The 'File Manager' icon in the Unity launcher opens my Home folder. How can I get it to open my Documents folder instead?

From Dev

The 'File Manager' icon in the Unity launcher opens my Home folder. How can I get it to open my Documents folder instead?

From Dev

Can I alter nautilus file manager through config files?

From Dev

How can I make an autorun to make a program open a file automatically

From Dev

How do I open my code file with sublime text without it opening my previous files on other tabs

From Dev

How do I open my code file with sublime text without it opening my previous files on other tabs

From Dev

How do I change the default file manager back to Nautilus?

From Dev

How do I change the default file manager back to Nautilus?

From Dev

How do I set Nautilus as default file manager in Elementary OS

From Dev

How can I set a shortcut key to open the currently selected file in nautilus?

From Dev

How can I make my page.open() requests sequentially?

From Dev

How to make web page remember last open file directory?

From Dev

How can I make all applications use Nemo's file selection dialog instead of Nautilus?

From Dev

How can I make all applications use Nemo's file selection dialog instead of Nautilus?

From Dev

How can I make jQuery open only post links in new tabs in Wordpress for this code

From Dev

How can I transfer all of my open tabs in Chrome in Android to Chrome on a desktop?

From Dev

How can I make tabs with only CSS?

From Dev

How can I make bat file open Excel files with quotes?

From Dev

How can I make two files open automatically in a .bat file?

From Dev

How can I redirect my jfreecharts into the tabs?

From Dev

{Android} How can I open my text file from uri?

From Dev

How can i use a button to open an xml file in my project

From Dev

How do I make sudo remember my password for longer?

Related Related

  1. 1

    Nautilus File Manager closes immediately I open it

  2. 2

    How to make nautilus the default file manager in LXDE

  3. 3

    How to make nautilus the default file manager in LXDE

  4. 4

    How can I get the Nautilus file manger to open?

  5. 5

    How can I open a folder in Atom editor directly from within my file manager's context menu?

  6. 6

    How to open Ubuntu Gnome 16.04 Nautilus (File Manager) preferences?

  7. 7

    The 'File Manager' icon in the Unity launcher opens my Home folder. How can I get it to open my Documents folder instead?

  8. 8

    The 'File Manager' icon in the Unity launcher opens my Home folder. How can I get it to open my Documents folder instead?

  9. 9

    Can I alter nautilus file manager through config files?

  10. 10

    How can I make an autorun to make a program open a file automatically

  11. 11

    How do I open my code file with sublime text without it opening my previous files on other tabs

  12. 12

    How do I open my code file with sublime text without it opening my previous files on other tabs

  13. 13

    How do I change the default file manager back to Nautilus?

  14. 14

    How do I change the default file manager back to Nautilus?

  15. 15

    How do I set Nautilus as default file manager in Elementary OS

  16. 16

    How can I set a shortcut key to open the currently selected file in nautilus?

  17. 17

    How can I make my page.open() requests sequentially?

  18. 18

    How to make web page remember last open file directory?

  19. 19

    How can I make all applications use Nemo's file selection dialog instead of Nautilus?

  20. 20

    How can I make all applications use Nemo's file selection dialog instead of Nautilus?

  21. 21

    How can I make jQuery open only post links in new tabs in Wordpress for this code

  22. 22

    How can I transfer all of my open tabs in Chrome in Android to Chrome on a desktop?

  23. 23

    How can I make tabs with only CSS?

  24. 24

    How can I make bat file open Excel files with quotes?

  25. 25

    How can I make two files open automatically in a .bat file?

  26. 26

    How can I redirect my jfreecharts into the tabs?

  27. 27

    {Android} How can I open my text file from uri?

  28. 28

    How can i use a button to open an xml file in my project

  29. 29

    How do I make sudo remember my password for longer?

HotTag

Archive