How to Set Close-Laptop-Lid Action in Ubuntu 17.10

17.10standbysystemdsystemd-logind

In Ubuntu versions before Gnome Shell, I could set what I wanted to happen when I close the laptop lid depending on whether the laptop is connected to power or not.

Now the default is standby which I can disable in Gnome Tweak Tool. My preferred setting is to only go to standby when on battery and stay on when connected to AC.

Using systemd I only know of options to completely enable or disable lid-actions alltogether. How did Unity solve this in Ubuntu 17.04?

Best Answer

This appears to be bug in the gnome-settings-daemon.

A workaround has been proposed by Kim Nguyễn in the form of a python script, custom_suspend.py. He/she says:

The script should be launched as: systemd-inhibit --who=me --why=because --mode=block --what=handle-lid-switch /path/to/custom_suspend.py

from the session startup (gnome-session-properties)

This is public domain and only lightly tested. It relies on existing gnome/systemd commands to perform the underlying action