1

Elementary OS's file manager opens the last working directory whenever we launch that file manager.

How can I write a script for Nautilus which will work same as given example above?

pomsky
  • 68,507

1 Answers1

1

Nautilus does not keep trace of the last opened folder
But, it keeps trace of recent open files. See Recent section in Nautilus

The following 'Ask' gives a good answer : close Nautilus while saving Tabs state
A bit tricky but works: How can I make Nautilus file manager remember my open tabs?

This script opens Nautilus on the folder of the last opened file
This can be called by a custom launcher nautilus-last-file.desktop

#!/bin/bash
LastFolder=$(grep -m1 'bookmark href' '~/.local/share/recently-used.xbel' | cut -f2 -d"\"" | cut -c 8-)
LastFolder=$(printf '%b' "${LastFolder//%/\\x}")
LastFolder=$(dirname "$LastFolder")
/usr/bin/nautilus "$LastFolder"
cmak.fr
  • 8,696
  • Why do $(which nautilus) "$LastFolder" instead of simply nautilus "$LastFolder"? Also, since recently-used.xbel is XML, you can use XML tools to accurately parse it: xmlstarlet sel -t -m '//bookmark' -i '(position()=1)' -v '@href' ~/.local/share/recently-used.xbel (albeit needing additional installation) – muru Jun 23 '18 at 17:53
  • @muru: removed the which... i did select grep because its very fast in handling large text files and because i wanted a out-of-box feature. Of course xmlstarlet do elegant work on xml files but it have to be installed. – cmak.fr Jun 24 '18 at 12:07