GNOME session save and restore

Save and restore your GNOME Shell desktop active running application windows and their positions across multiple workspaces using an automated command line script.

Synopsis:

To save your session, press Alt+F2 or on a terminal:

>session save

To restore your session, press Alt+F2 or on a terminal:

>session restore

To restore your session including running applications:

>session restore missing

Installation:

Dependencies:

This script uses Perl, xprop+xwininfo, wmctrl, and optionally xdotool. To ensure that all dependencies exist use:

>sudo yum install -y perl xorg-x11-utils wmctrl xdotool

Note: I only test on my CentOS desktops. Others have reported the script working on Ubuntu, Xubuntu, and other desktops.

Download the script
Place it on your $PATH, and be sure to give it executable permissions:

>wget https://github.com/arnon-weinberg/session/raw/master/session
>chmod +x session
>sudo mv session /usr/local/bin

Use cases:

  • Restore workspace after reboot from kernel upgrade, hardware upgrade, non-recoverable error, battery died, or power outage.
  • Desktop layout messed on laptop after unplugging from an external monitor.
  • Restarting an application with multiple windows across workspaces.
  • Reopen application that crashed or was closed accidentally.
  • Remember and automatically restart open running active apps.
  • Reset application window geometries and arrangements over multiple desktop workspaces using command line or script.

Details:

>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

Available options:
–session: Set session filename [default = ~/.config/gnome-session/session.ini]
–debug=[0-3]: Set debug level

Limitations:
Restoring applications (session restore missing) only runs applications; it cannot restore their previous state – that is up to each application to do.
The script contains a list of exceptions that is currently manually maintained. It lists applications that should be handled specially when restoring them. Because some applications handle their own session save and restore, but they don’t handle restoring geometries, the session restore process can be a 3-step process sometimes: (1) Run session restore missing to restart the application, (2) follow the application’s session restore process, and (3) run session restore to restore its geometries.

Note: The session script never shuts down applications, and simply ignores applications not in the saved session.

Changes:

Relative to the previous version of this script, this upgrade has a much improved window matching algorithm, application running process, updates for recent applications, and fixes for several bugs.
The command line arguments have changed.

This script is now on GitHub.

2 comments to GNOME session save and restore

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>