Python script to store and load your preferred desktop layout
Are you tired of having to load, place and resize the programs you normally use every time you start your computer? Would you like to have a simple program that does it for you automatically? Do you wish easily to switch from a series of programs oriented to different uses (office, internet, multimedia, CAD and 3D)? In the article I propose all this by presenting an easy-to-use Python script for Ubuntu and derivatives.
What is it for?
It takes care of saving in a text file the layout of your favorite applications with their position and size in the correct workspace and uploading them whenever you need them, for example when you start your PC or when you switch from one use to another.
As shown in the video below:
The name of the script is recall_windows and it is written in Python, I found it on askubuntu in this thread Is there a way to store the current desktop layout?.
I have added two features in order to:
- read and store windows displacement considering also the workspace;
- add a filename option to have different layout displacements.
How it works: Read
Once loaded, positioned and sized your applications, you have to launch this command:
recall_windows -read (it will save the layout in a file called .windowlist in your $HOME folder)
recall_windows -read nomefile (it will save the layout in a file called .nomefile in your $HOME folder)
I always suggest you to check the generated file and eventually fix it, because it doesn't read correctly the binary of the applications and their position, every row contains an application described by 7 columns as follow:
- binary of the program
- workspace number
- program ID
- horizontal position in pixel from left to right
- vertical position in pixel from top to bottom
- width in pixel
- height in pixel
In my case it creates this file:
xfce4-terminal 2 26387 652 74 577 357 Thunar 1 1405 2 73 954 1023 corebird 2 26424 -26 2 699 598 opera 2 26443 655 327 1236 868 chrome 0 26624 0 25 1920 1055 gnome-system-mo 2 26809 1222 74 700 523 Telegram 2 2405 3 596 647 500
That I had to correct in this manner:
xfce4-terminal 2 12284 650 26 577 357 Thunar 1 11905 0 25 954 1023 corebird 2 12318 -26 2 699 598 opera 2 12337 653 279 1236 868 chrome 0 12798 0 25 1920 1055 gnome-system-monitor 2 13034 1220 26 700 523 /home/nicola/Programmi/Telegram/Telegram 2 13041 2 572 647 500
How it works: Positioning
In order to store the applications, you have to launch the following command:
nohup ./recall_windows -run (it stores the file called .windowlist in your $HOME folder)
nohup ./recall_windows -run nomefile (it stores the file called .nomefile in your $HOME folder)
nohup execute commands after you exit from a shell prompt
Obviously you can create a bash script at boot like this:
#! /bin/bash sleep 5 wmctrl -s 0 $HOME/Script/recall_windows -run exit 0
You can download it from GitHub:
- GitHub: ../recall_windows