DEV Community

Johannes Millan
Johannes Millan

Posted on

Restore applications and their positions from the command line on linux desktops

LWSM is an open source library / command line tool that lets you save and reload your opened programs and the positions of their windows.
Supports Unity and Gnome Desktops and possibly all other compositing window managers using X (including XWayland).

Installation

NodeJs needs to be installed.

npm install -g linux-window-session-manager

For older distros, you also might need to install the locate command via sudo apt-get install mlocate.

Updating

npm update -g linux-window-session-manager
# (optional) delete config to update it to the newest version
rm ~/.lwsm/config.json

CMD Usage

Saving a session:

# save the current session to ~/.lwsm/sessionData/DEFAULT.json
lwsm save

# save the current session to ~/.lwsm/sessionData/my-session.json
lwsm save my-session   

Note that the session are stored for the specific display combination, you're currently running. If you want to store a different layout for when you have an external monitor plugged in this is possible. Just run the save command again for the same session.

Restoring a session:

# restore the session from ~/.lwsm/sessionData/DEFAULT.json
lwsm restore

# restore the session from ~/.lwsm/sessionData/my-session.json
lwsm restore my-session   

# gracefully close all running apps before starting the session
lwsm restore --closeAllOpenWindows

List saved sessions:

lwsm list

Rename a saved session:

lwsm rename oldName newName

Adjusting the configuration:

You can manually edit the config file present at ~/.lwsm/config.json and the session files in ~/.lwsm/sessionData/[sessionName].json.

Command-line completion:

# Automatically install command-line completion
lwsm --setupCompletion
# Generate command-line completion code for bash and zsh shells for manual installation
lwsm --completion
# Generate command-line completion code for fish shell for manual installation
lwsm --completion-fish

Command-line completion implemented by omelette, so you may refer it's README to check file where completion code will be added on automatic install.
Restart your shell after automatic install to apply changes.

Companion Tools

There's also a companion tool in form of an indicator applet, a gnome-shell-extension and a Ulauncher extension if you like such things but this package can also be used standalone.

Top comments (0)