I made a script that saves and reloads your window locations

Something better might exist, and I’m sure people will scoff at my choice of language (PHP). I made this because I regularly log off and on my computer and got sick of reloading windows that I had open.

This code was developed and tested on Pop OS 20.04 and is expected to work with any Ubuntu flavored distribution.

Q: Why PHP?
A: It’s the language I know the best right now. When I’m more comfortable with shell scripting or python, I may rewrite it for fun.

Q: Why did you make this?
A: I have a GPU pass-through setup that hot swaps my graphics card, and doing this gracefully requires turning off my display manager, thus closing all my windows. Using this script allows me to reopen my configured windows automatically. I literally use this script everyday!

Q: Is it only for application windows or it can reopen browser tabs as well?
A: This is only for application windows. The script will try to reopen the windows based upon the command it sees in the process list. This is not always accurate so after you save your windows you may want to populate the override command section for your window with the correct terminal command that will launch the application you were trying to save. For browser tab restoration, I’m just relying on Firefox to save the tabs for me.

Q: If I have an unsaved notepad and upon calling this script before logging out to save, does this script restore the notepad contents as well after logging back in?!
A: No, the script only opens the program back up and moves it to where it was when you saved your window settings. However, this script pairs will with text editors like Notepadqq which will restore unsaved text content if you set the options to do so.

4 Likes

Erm, I don’t really like this feature, but AFAIK most desktop managers have option to save and restore desktop session. It doesn’t work for you in yours or something?

That’s a really good question. I tried using linux-window-session-manager (as described in this article https://www.linuxuprising.com/2018/04/gnome-save-and-restore-running.html), but it was half broken and I was never able to get it to restore my windows. It might work just fine for some folks, but instead of trying to make a plugin work for my environment, I instead looked into how to manipulate the x windows and this script was born.