I am using Mint 20.2 with Cinnamon. One of the features I miss from my Windows days is the built-in function to remember open folder browser (i.e. Windows Explorer) windows and reopen them after reboot.
After some sleuthing I figured how to manually list/save the windows before shutdown and automatically reopen them after boot. But I can't get Mint to automatically run the list/save before logout – before the desktop environment closes.
First, what works for me:
1) You must turn on Nemo's "Show the full path in the title bar"
- Open the Nemo file (folder) browser
In the menu choose Edit – Preferences – Display – Show the full path
Reload the browser for each currently open window
list-for-reboot.sh
Code: Select all
#!/bin/bash
wmctrl -l -x > /home/$USER/Documents/wmctrl.txt
read -p "(r)estart or (s)hutdown ? or just Enter to quit. " answer
if [[ "$answer" == 'r' ]]
then
systemctl reboot
elif [[ "$answer" == 's' ]]
then
systemctl poweroff
else
echo "neither r nor s, so nothing."
fi
Code: Select all
#!/bin/bash
# this depends on Nemo - Edit - Preferences - Display - Show the full path
file="/home/$USER/Documents/wmctrl.txt"
while read -r f1 f2 f3 f4 f5
# display fields of "wmctrl -l -x" using f1, f2, ...
# f1 is window number 0xnnnnnnnn
# f2 is workspace number 0,1,2,3 or -1 for "sticky" Desktop
# f3 is WM_CLASS (name of running process)
# f4 is hostname
# f5 is window title (catch all remaining characters)
do
# echo "1=$f1 2=$f2 3=$f3 4=$f4 5=$f5" # (for debugging)
if [[ "$f3" == 'nemo.Nemo' ]]; then
# is this just Home ?
if [[ "$f5" == 'Home' ]]; then
nemo "$HOME" &
# is this smb or local directory ?
elif [[ "$f5" == *smb:* ]]; then
nemo "smb:${f5#*smb:}" &
else
# slash is used as delimiter to find substring, so open
# browser at: / plus substring after first slash in f5
nemo "/${f5#*/}" &
fi
fi
done <"$file"
# wipe the wmctrl.txt file so "old" windows don't get opened
# if there is a normal reboot/shutdown through menu panel
>"$file"
with either a chmod command or right-click, Properties, Permissions
3) Create a Launcher for the list-for-reboot.sh script. I chose a corner on my desktop:
- right-click, Create a new launcher here
Name: List open windows for reboot
Command:/home/$USER/Documents/list-for-reboot.sh
Check: Launch in terminal
- Menu – Startup Applications
Click the + to add a new item, choose Custom Command
Name: Reopen windows at boot
Command:/home/$USER/Documents/reopen-at-boot.sh
Application windows (pdf, editor, mail, terminal, ...) are listed at shutdown, but they are not opened at boot. I don't want that – you can add more tests to the boot script. Just run "wmctrl -l -x" in a terminal, or run the "List open windows" and quit, then look at the wmctrl.txt file.
Now what doesn't work for me:
I read all I can find on how to automatically run a script at logout and/or shutdown. I tried Ubuntu run levels, lightdm session-cleanup, systemd services, .profile, .logout, and X11 server. They run the script AFTER the desktop closes, so there is nothing for WMCTRL to list. None of them have a "before LOGOUT" option. Cinnamon does not have a Shutdown Applications feature.
Does anyone know how to run a script as the last thing BEFORE the desktop closes? That would make this process fully automatic.