0

Is there any way to save the Nautilus state? I'm usually opening more windows and more tabs, divided by arguments, but it's very frustrating to lose them every time I shutdown the system.

tigerjack
  • 2,575
  • 7
  • 25
  • 38
  • You can choose hibernate instead of shutdown – Pandya Sep 19 '14 at 08:38
  • @Pandya sure, but it isn't the same thing. Also, hibernation often arise many problems and sooner or later I'm forced to shutdown the system. – tigerjack Sep 19 '14 at 08:41
  • 1
    Have you tried this?

    http://askubuntu.com/questions/52112/remember-what-directories-are-open-in-one-session-of-nautilus

    – MrV Sep 19 '14 at 08:58
  • @MrV don't know exactly how it works, I just tried to type nautilus --sm-client-state-file ~/.config/session-state/nautilus-xxxxxxxxxx.desktop & and it returns Could not parse arguments: Unknown option --sm-client-state-file

    Also, nautilus man doesn't contain anything about this.

    – tigerjack Sep 19 '14 at 09:08
  • Did you try the session saving suggestion too? – Nattgew Sep 19 '14 at 16:26
  • @Nattgew As I can read, the feature was broken and removed. Also, it may be a workaround; however, I don't want to save the whole session, just the nautilus status. – tigerjack Sep 19 '14 at 16:31
  • Could you write a script to open them? – Nattgew Sep 19 '14 at 16:35
  • @Nattgew unfortunately, I'm not capable of do this sort of thing. Also, the scripts should be "interactive" in some way; i.e., it should be able to 1) memorize currently opened tabs in some way (like a text file); 2) reopen the directories if I want to. Maybe it is yet possible to do this by command line, but I don't know how. – tigerjack Sep 19 '14 at 16:43

2 Answers2

2

There isn't a (simple) way to do this, but this question has a script that can help:

open nautilus as new tab in existing window

Note that xdotool and wmctrl need to be installed for it to work.

Using that script as a basis, you could make a script that automatically opens a defined set of windows and tabs. This is just to give a general idea and not tested. For example, I don't know how wmctrl would work with multiple Nautilus windows. I'm sure the loops/variables/quotes could be better too (I'm not attempting to simulate a 2D array yet).

windows=2
tabs1=(/home/user/Documents /home/user/Downloads)
tabs2=(/usr/share /etc)

#Save old clipboard value
oldclip="$(xclip -o -sel clip)"

#The following would be the cleanest way to code this:

#while i < $windows; do
    #open nautilus
    #for tab in tabs; do
        #open tab in this window
    #done
#done

nautilus ${tabs1[0]}

for tab in ${tabs1[@]}; do
    i=0
    for tab in ${tabs[@]}; do
        if [ $i -gt 0]; then
            echo -n tab | xclip -i -sel clip
            wmctrl -xF -R nautilus.Nautilus && xdotool key ctrl+t ctrl+l ctrl+v Return
        fi
        i=$[$i + 1]
    done
done

#Restore old clipboard value
echo -n "$oldclip" | xclip -i -sel clip

The best way to do this would be to loop through all windows and all tabs. It would open Nautilus with tab 1, then open tab 2, etc. It uses the clipboard to store the tab location, and pastes it in to the location field.

You would need to manually set the number of windows and the tabs in each one before each shutdown. But I realized you could use the script in reverse to save the open tabs:

#Save old clipboard value
oldclip="$(xclip -o -sel clip)"

wmctrl -xF -R nautilus.Nautilus && xdotool key ctrl+l ctrl+c
tab=$(xclip -o -sel clip)
tabs[0]=""

i=1

while [ "$tab" != "$tabs[0]"]; do
    tabs[i]="$tab"
    wmctrl -xF -R nautilus.Nautilus && xdotool key ctrl+l ctrl+c
    tab=$(xclip -o -sel clip)
    i=$[$i + 1]
done

#i=1

#while i < $windows; do
    #open window, open tabs?
#done

#Restore old clipboard value
echo -n "$oldclip" | xclip -i -sel clip

That's about all I can do at the moment. I may try to test this later, and any suggestions/fixes are welcome.

Nattgew
  • 2,100
  • Thanks for your help :) Btw, I haven't understood how to proceed with the scripts. The "#while i < $windows; do" and following lines are just an explanation of what happens in the next lines or it's just pseudocode waiting for a right way to implement? – tigerjack Sep 20 '14 at 08:53
  • Yeah, that's just pseudocode for the simplest loop, if the variables can be worked out. – Nattgew Sep 22 '14 at 16:29
1

In the case of windows, it's possible to make a custom launcher which opens all URIs specified.

You can see the file /usr/share/applications/nautilus-home.desktop. There is a line starting with Exec:

Exec=nautilus --new-window %U

You can change it in this way:

Exec=nautilus -n URI1 URI2 …

After you save it somewhere such as your desktop and check the executable permissions, it will open each specified URI in a separate window.

AliNajafies
  • 5,874
  • Thanks :) Indeed, it seems useful. The problem now is: how can I store the URI of my tabs before I shutdown the system? – tigerjack Sep 20 '14 at 08:55