How to save and restore a desktop icons positions in MATE?

I have read and tried a solution posted in the answer to what is essentially the same question as with the result:

ykarant@equality-HP-ZBook-15-G2:/opt/ykarant$ ./recall-windows -read
Traceback (most recent call last):
  File "./recall-windows", line 87, in <module>
  File "./recall-windows", line 32, in read_windows
    res = get_res()
  File "./recall-windows", line 26, in get_res
    curr_vpdata = [int(n) for n in vp_data[5].split(",")]
  File "./recall-windows", line 26, in <listcomp>
    curr_vpdata = [int(n) for n in vp_data[5].split(",")]
ValueError: invalid literal for int() with base 10: 'N/A'

Ubuntu 20.04 LTS current, MATE current.

After a "glitch", when the desktop started, all of the icons that represent applications on my desktop were moved about on the desktop, some stacked upon one another. I am looking for a mechanism to "save" the current desktop configuration (not necessarily which applications were open, nor on which Workspace Switcher virtual desktop such applications were open -- merely the actual layout of the desktop icons).

Is there an application or "script" that does this "save and restore" for MATE or for other equivalent GUI interfaces?

Have you ever tried to use built-in MATE session restore functionality?

Go to MATE Control Center, select Startup Applications (or directly by mate-session-properties), switch to Options tab and check Automatically remember running applications when logging out

and then logout or reboot.

It is not the running applications. It is the layout of non-running applications activation icons that appear on the desktop. There are only a few GUI applications that I routinely start, and these I manually can start. However, I need to be able to locate applications that I use, and these I place on the desktop (that may look cluttered to some, but follows rules that allows me efficiently to find what I need). I can provide a screenshot of my current desktop layout if that would help to understand my need.


Then you have to setup special application named RaySession to your needs.


Install it by sudo apt-get install raysession .

See its manual for details. It is wmctrl-based, so should do the job.

Second thing to try is

RaySession Manual

for version 0.10.0


RaySession is an audio session manager for GNU / Linux. It allows you to start several audio programs in the same session, to save their projects together and thus to avoid multiple operations to return to a given configuration. End quote.

Thus, RaySession is for audio, not a desktop, and is a pre-production release -- thus, with no assumption of reliability. AND


Python-based command line tool to save and restore sessions for X11 desktops like Gnome, and other features to maintain sessions. The project is currently in an early stage of development.

This project was written in Bash originally. But now I'm completely rewriting it in Python which obviously makes it way more flexible, extensible.

This project relies on wmctrl, which is why you have to install it beforehand. End excerpt.

xsession-manager clearly claims to be pre-production as well. Has no such save and restore of the desktop layout been released for a production (post-beta, 1.x or higher release) environment? I will test xsession-manager and report what I find -- but I am not enthusiastic about debugging what should be a standard feature of (almost all) applications (save state and restore state).

Trying xsm:

ykarant@equality-HP-ZBook-15-G2:~$ xsm
sh: 1: twm: not found
^CICE default IO error handler doing an exit(), pid = 6856, errno = 11
ykarant@equality-HP-ZBook-15-G2:~$ sudo apt install twm
Reading package lists... Done
Processing triggers for menu (2.1.47ubuntu4) ...
ykarant@equality-HP-ZBook-15-G2:~$ xsm
twm:  another window manager is already running. on screen 0?
twm:  unable to find any unmanaged video screens.
^CICE default IO error handler doing an exit(), pid = 7402, errno = 11

ykarant@equality-HP-ZBook-15-G2:~$ man xsm

I can reproduce the man page for xsm if you wish. It is not clear if xsm will work with other than twm nor if xsm actually restores a desktop configuration but rather "running" applications.

Question: there must be a configuration file or directory (evidently not Desktop, as this has the widgets for each icon on the desktop, but not the location on the desktop in so far as I can find) that holds the position of each widget on the desktop. How does one find this file (I would merely make an exact copy, save the copy, and then copy the copy back to the file/directory used to determine the layout)? As there is permanence between shutdown/boot cycles, the file must be stored on the drive (magnetic or SSD) as it is not installed into NVRAM.

@YKar First of all I would like to thank you for this topic.

You are raising interesting and useful topic. I have never used neither RaySession, nor xsm. I did a search to find them. But personally I care about session save and restore of running applications in Ubuntu MATE.

Really there is xsm binary in the system.
In default Ubuntu MATE 20.04 LTS xsm is already installed, it came from

$ which xsm 
$ dpkg -S $(which xsm)
x11-session-utils: /usr/bin/xsm
$ whereis xsm
xsm: /usr/bin/xsm /usr/share/man/man1/xsm.1.gz

And it is not what we need.

So we need to install real xsession-manager (xsm from Github):

sudo apt-get install python3-dev wmctrl python3-pip python3-tk curl libcurl4-openssl-dev libssl-dev python-is-python3

sudo pip3 install xsession-manager

and then launch xsm. The bad news here is that it does not work and shows error:

$ xsm
Traceback (most recent call last):
  File "/usr/local/bin/xsm", line 8, in <module>
  File "/usr/local/lib/python3.8/dist-packages/xsession_manager/", line 10, in run
  File "/usr/local/lib/python3.8/dist-packages/xsession_manager/", line 27, in check_login_condition
    original_login_user = os.getlogin()
OSError: [Errno 6] No such device or address

I have reported above as bug to GitHub .
We can fix this bug locally by

sudo sed -i "s|os.getlogin()|os.getenv('LOGNAME')|" /usr/local/lib/python3.8/dist-packages/xsession_manager/

Then xsm needs further analysis and testing.
Currently I'm not sure that it supports position/geometry restoring for window manager.

Thank you for your work into finding a solution for saving the appearance of a MATE desktop, not the state of applications running in a user MATE desktop window. Are you familiar with the internals of MATE (I am not)? If so, the layout (not just the files in Desktop that contain the executable displayed name, path, and icon, but the actual position on the desktop) must (should be?) stored somewhere, either as a permanent file or in a temporary file (or perhaps a directory with subfiles, as in some database-style designs). If one knows that path, it is a simple matter (perhaps as root) to copy and later restore such a file/directory.

MATE uses Marco as window manager. Marco runs inside Xorg session.

All windows may be controlled by wmctrl. See man wmctrl locally or online. Both found applications use wmctrl under the hood.
For example to list all application windows you can run wmctrl -lpG (this is what xsm did on xsm -s).
On xsm -r it loads window configuration from its config file. But currently it can't restore window geometry. I have written feature request about this

Theoretically RaySession will work if we use number of Executables. Feature request about restoring window position was filed .

So at time of writing both xsm and raysession allow user to save and restore application window lists without their geometry settings.

About initial recall-windows script - it was written 6 years ago, so some things may change. It does not look universal.

On GitHub there are other users-written scripts. The most promising is Perl-based session). You can read more about it in the author's blog and then install it with:

sudo apt-get install wmctrl

chmod +x session
sudo mv session /usr/local/bin

Then use the following syntax:

  • session save: Save session in default location (see below)
  • session restore existing: Restore geometries of existing windows
  • session restore matching: Restore geometries of matching windows [default]
  • session restore missing: Restore geometries of missing windows

I have tested it with 3 windows on MATE. Seems to work good.

I followed your instructions. The default location of the output ("saving") file is
Output file of the session application:

$session = {
             '0x01200003' => {
                               'geometry' => '10,0,0,1920,36',
                               'exec' => [
                               'id' => '0x01200003',
                               'state' => {
                                            '_NET_WM_STATE_FOCUSED' => 1,
                                            '_NET_WM_STATE_STICKY' => 1,
                                            '_NET_WM_STATE_SKIP_TASKBAR' => 1,
                                            '_NET_WM_STATE_SKIP_PAGER' => 1
                               'name' => 'equality-HP-ZBook-15-G2 Top Panel',
                               'comm' => 'mate-panel',
                               'workspace' => '-1',
                               'pid' => '3342',
                               'command' => 'mate-panel',
                               'class' => 'mate-panel.Mate-panel',
                               'Name' => 'Mate-panel'
             '0x06800003' => {
                               'geometry' => '10,77,89,1805,924',
'exec' => [
                               'id' => '0x06800003',
                               'state' => {},
                               'name' => 'equality-HP-ZBook-15-G2 How to save and restore a desktop layout in MATE - Support & Help Requests - Ubuntu MATE Community — Mozilla Firefox',
                               'comm' => '/usr/lib/firefox/firefox',
                               'workspace' => '1',
                               'pid' => '11510',
                               'command' => '/usr/lib/firefox/firefox',
                               'class' => 'Navigator.Firefox',
                               'Name' => 'Firefox'
             '0x01200017' => {
                               'comm' => 'mate-panel',
                               'name' => 'equality-HP-ZBook-15-G2 Bottom Panel',
                               'state' => {
                                            '_NET_WM_STATE_STICKY' => 1,
                                            '_NET_WM_STATE_FOCUSED' => 1,
                                            '_NET_WM_STATE_SKIP_TASKBAR' => 1,
                                            '_NET_WM_STATE_SKIP_PAGER' => 1

and this sort of output continues. The application does save open windows and the geometry of these, but does not appear to be saving the non-open application icons on the desktop.

The session restore missing should restore closed windows.
If it fails - then use session restore missing followed by session restore .

This needs comments. What do you mean here?

Evidently, this list does not have the same character limits in a reply as does the Ask Ubuntu list; thus, I do not need to be as succinct as on the Ubuntu list. My desktop has a large number of icons that represent the [Desktop Entry] (when one right clicks on the icon and opens with a text viewer/editor -- a plain text file related to each desktop icon). Most of these do not appear in the save file with a coordinate set representing the location of each on the desktop; thus I summarized this concept with "saving the non-open application icons on the desktop". I should have stated the "saving the desktop location of the non-open ... ".

This sounds strange. It is OK for GNOME. But on MATE it should open the application itself, not text-editor. For example if I drag Firefox icon from Brisk/Applications menu and drop it to desktop, then double-click it - the Firefox will be launched (not text editor).
What are the contents of ~/.config/mimeapps.list file in your system?

I am confused by your response. On a right click upon an icon (I use a standard unix 3-button pointing device), I see a popup list that has open (that "runs" the command "pointed to" by the desktop icon) and open with that allows one to edit the desktop entry. However, the point of my enquiry was to find a method to save the positions of the icons (that point to commands/applications) on the desktop. If there exists a file, directory, directory tree, whatever, that I can copy and subsequently restore, my request would be resolved.

I/we started the walk on wrong way. Initially you have found a script for saving window positions. So I was thinking about saving restoring MATE session. Like if it was macOS where system opens windows of all applications from previous boot.

But now you are talking about icons. I can't understand this. Icons are usually save their positions on desktop without any additional software. Caja do this for us. This may break if you have two (or more applications) which control desktop area. Do you have installed Nemo and/or Nautilus on the same system?

You are correct that once arranged, icons retain the position on the desktop to which each has been assigned -- or at least are supposed to do so. However, the system (X11? MATE? something else?) "glitched" after an update suggested by the Ubuntu Software Updates GUI applications -- and all of the positions were lost, with ten or more (I no longer remember the exact number) of icons placed onto the same desktop location, making none usable, all after an exit from my user GUI account (this might have been a reboot -- I no longer recall). (I fixed this by repeated "drag and drop" of the "top" icon to some other location until all were visible -- on my system, the "stack" was in the upper right corner of the desktop.) So that I do not have to do this again, I would appreciate a mechanism to save and restore the desktop icon locations. If this involves simply archiving one or more files, directories, or directory trees, I will do this once I know what to save. Call this top-level directory "foo" under /some-path/foo . Then, as root, cp -pr /some-path/foo /opt/saves/foo-save and the inverse operation to restore. Am I now more clear? Take care. Stay safe.

I suppose that this may be permissions issue. For sure fix the permissions of the configuration folders by:

sudo chown -R $USER:$USER ~/.config ~/.cache ~/.local

I just did what you suggested. However, for my own reassurance, I truly would appreciate if you (or someone) who understands the internals of MATE kindly would tell me which files/directories/directory trees in which MATE, X11, or whatever, keeps the locations on the displayed desktop of the actual desktop icons. This does not appear to be in the directory ~/Desktop that merely has the list of "icon" files that will be displayed -- not the desktop location at which the "icon" will be displayed. Once I know the location of the desktop location information (cached or otherwise, including in a systems file that only root may access), I will make a backup copy that I may restore when such is needed. Note that if there is an upgrade of MATE, I will first make a copy of the post-upgrade version in case the upgrade is not backward compatible with the previous (minor or major) release version.

The file of interest seems to be the following:


You have to check its permissions and contents by commands below:

ls -al ~/.local/share/gvfs-metadata/home
gio info ~/.local/share/gvfs-metadata/home
1 Like

I have made a copy, moved icons around on the desktop, and then logged out, logged in, and restored what I had copied. The icons again stacked in the upper right corner of the desktop. After this exercise, I display below the ls -la of both the original and saved files. Clearly, these files seem to contain the correct information, but somehow it does not seem to restore quite correctly. For now, I am keeping a screenshot of the current desktop layout so that at least I may manually restore things in the future. An "automatic" restore would be nice. Notice in the gvfs-metadata directory there are "automatically" backed-up copies of home with various extensions with past dates. What would be useful is a utility that did the manual save and the permitted a proper manual restore (a straight restore via a copy seems to not keep things in the correct location -- perhaps a Software Updater recommended update of some entity changed the way the "coordinates" are measured/described?

ykarant@equality-HP-ZBook-15-G2:~$ ls -la ~/.local/share/gvfs-metadata/*home*
-rw------- 1 ykarant ykarant 374404 Mar  1 13:03 /home/ykarant/.local/share/gvfs-metadata/home
-rw-rw-r-- 1 ykarant ykarant  32768 Mar  1 13:03 /home/ykarant/.local/share/gvfs-metadata/home-2c92a3a1.log
-rw-rw-r-- 1 ykarant ykarant  32768 Mar  1 12:38 /home/ykarant/.local/share/gvfs-metadata/home-6add20ad.log
-rw-rw-r-- 1 ykarant ykarant  32768 Mar  1 12:41 /home/ykarant/.local/share/gvfs-metadata/home-c1a40386.log
-rw------- 1 ykarant ykarant 360588 Feb 18 10:17 /home/ykarant/.local/share/gvfs-metadata/home.UPGVY0
-rwxr-xr-x 1 ykarant ykarant   4140 Oct  9 22:13 /home/ykarant/.local/share/gvfs-metadata/home.X0RKS0
ykarant@equality-HP-ZBook-15-G2:~$ ls -la ~/saves-gvfs/gvfs-metadata/*home*
-rw------- 1 ykarant ykarant 374404 Mar  1 08:07 /home/ykarant/saves-gvfs/gvfs-metadata/home
-rw-rw-r-- 1 ykarant ykarant  32768 Mar  1 08:07 /home/ykarant/saves-gvfs/gvfs-metadata/home-8f4c6a45.log
-rw------- 1 ykarant ykarant 215060 Nov 14 19:09 /home/ykarant/saves-gvfs/gvfs-metadata/home.T57FU0
-rw------- 1 ykarant ykarant 360588 Feb 18 10:17 /home/ykarant/saves-gvfs/gvfs-metadata/home.UPGVY0
-rwxr-xr-x 1 ykarant ykarant   4140 Oct  9 22:13 /home/ykarant/saves-gvfs/gvfs-metadata/home.X0RKS0