Linux laptop lid close

Laptop Lid and Dock Scripts

NOTES: — The material here was tested in Ubuntu 10.04. The computers used were a Lenovo Thinkpad T61 and a T61p. Things might slightly change depending on the laptop or Linux distribution. But the main idea will be the same. This tutorial is just to point people towards the right solution.

Laptop Lid Open/Close Scripts

It is important to understand that these events will be caught by processes owned by root. A fix is needed to allow root to run processes in the normal user’s X environment. In order to make the environment variables available for root:

and paste the following in:

# Export the dbus session address on startup so it can be used by any other environment sleep 5 touch $HOME/.Xdbus chmod 600 $HOME/.Xdbus env | grep DBUS_SESSION_BUS_ADDRESS > $HOME/.Xdbus echo 'export DBUS_SESSION_BUS_ADDRESS' >> $HOME/.Xdbus # Export XAUTHORITY value on startup so it can be used by cron env | grep XAUTHORITY >> $HOME/.Xdbus echo 'export XAUTHORITY' >> $HOME/.Xdbus

Save and close. Then make it executable:

Now set it to run at startup. In Gnome 2, System> Preferences> Sessions and click Add. In Ubuntu Unity, click the gear icon in the upper right, select Startup Programs, and click Add.

Name: X Environment Variables Command: /home/your_user/export_x_info

This will execute every time you start your computer and the call to source ~/.Xdbus loads the DBUS_SESSION_BUS_ADDRESS and XAUTHORITY environment variables before executing the purple-remote command for Pidgin.

Ubuntu makes it easy to catch the laptop lid open and close events.

Firstly, you need to create (if it’s not there, that’s the case on Ubuntu 14.04) the /etc/acpi/events/lm_lid file and put:

event=button/lid.* action=/etc/acpi/lid.sh

After that, there is a file /etc/acpi/lid.sh which runs every time your lid open or closes. So run:

gksudo gedit /etc/acpi/lid.sh

and right after line #!/bin/bash paste /home/your_user/lid_event. Save and close.

Now create the file that will call different scripts according to open or close events.

and paste the following into the file:

grep -q closed /proc/acpi/button/lid/LID/state if [ $? = 0 ] then /home/your_user/close; else /home/your_user/open; fi

Save and close and make it executable.

And finally, create the files open and close.

Paste the following into the file:

#This runs so that root can run the following command under the user's environment source /home/your_user/.Xdbus #play a open sound DISPLAY=:0.0 su your_user -c "aplay /usr/lib/openoffice/basis3.0/share/gallery/sounds/sparcle.wav" #change Pidgin status DISPLAY=:0.0 su your_user -c "purple-remote 'setstatus?status=available&message=I am here. '"

Save and close. Make it executable:

Читайте также:  Installing linux source ubuntu

Now create the close file:

and paste the following into the file:

#This runs so that root can run the following command under the user's environment source /home/your_user/.Xdbus #play a close sound DISPLAY=:0.0 su your_user -c "aplay /usr/lib/openoffice/basis3.0/share/gallery/sounds/falling.wav" #change Pidgin status DISPLAY=:0.0 su your_user -c "purple-remote 'setstatus?status=away&message=My laptop lid is closed. '"

Save and close. Make it executable:

sudo /etc/init.d/acpid restart
  • Notes: — Make sure that the Power Management option for laptop lid closed is set to do nothing.
    — The sounds used are from OpenOffice 3.0, the path changes for other versions.
    — Make sure you have libpurple-bin installed — sudo apt-get install libpurple-bin.

Dock and Undock Scripts

Many laptops can be docked into a powered, cooled docking station. These scripts are meant to capture the dock/undock event and, in this case, play a sound.

This is done by creating and using a udev event.

gksudo gedit /lib/udev/rules.d/85-thinkpad-T61.rules
KERNEL=="dock.0", ACTION=="change", RUN+="/etc/thinkpad/dock.sh"

Create the docked script:

sudo mkdir /etc/thinkpad gksudo gedit /etc/thinkpad/dock.sh
# wait for the dock state to change sleep 1 DOCKED=$(cat /sys/devices/platform/dock.0/docked) case "$DOCKED" in "0") #undocked event /home/your_user/undocked ;; "1") #docked event /home/your_user/docked ;; esac exit 0

Save and close. Make it executable:

sudo chmod +x /etc/thinkpad/dock.sh

Next, create the undocked file:

#This runs so that root can run the following command under the user's environment source /home/your_user/.Xdbus #play a sound DISPLAY=:0.0 su your_user -c "aplay /usr/lib/openoffice/basis3.0/share/gallery/sounds/falling.wav"

Save and close. Make it executable:

#This runs so that root can run the following command under the user's environment source /home/your_user/.Xdbus #play a sound DISPLAY=:0.0 su your_user -c "aplay /usr/lib/openoffice/basis3.0/share/gallery/sounds/sparcle.wav"

Save and close. Make it executable:

Now finally we need to restart hal:

You now should be able to dock and undock and hear a sound each time you do. From here the options for you are endless.

LaptopLidAndDockScripts (последним исправлял пользователь athedsl-4412064 2015-09-06 20:57:35)

The material on this wiki is available under a free license, see Copyright / License for details
You can contribute to this wiki, see Wiki Guide for details

Источник

Why does my computer turn off when I close the lid?

When you close the lid of your laptop, your computer will suspend in order to save power. This means that the computer is not actually turned off — it has just gone to sleep. You can resume it by opening the lid. If it does not resume, try clicking the mouse or pressing a key. If that still does not work, press the power button.

Some computers are unable to suspend properly, normally because their hardware is not completely supported by the operating system (for example, the Linux drivers are incomplete). In this case, you may find that you are unable to resume your computer after you have closed the lid. You can try to fix the problem with suspend , or you can prevent the computer from trying to suspend when you close the lid.

Читайте также:  Linux узнать версию openssl

Stop the computer from suspending when the lid is closed

These instructions will only work if you are using systemd . Contact your distribution for more information.

You need to have Tweaks installed on your computer to change this setting.

If you do not want the computer to suspend when you close the lid, you can change the setting for that behavior.

Be very careful if you change this setting. Some laptops can overheat if they are left running with the lid closed, especially if they are in a confined place like a backpack.

  1. Open the Activities overview and start typing Tweaks .
  2. Click Tweaks to open the application.
  3. Select the General tab.
  4. Switch the Suspend when laptop lid is closed switch to off.
  5. Close the Tweaks window.

Источник

How to Change the Lid Close Action in Ubuntu 22.04 / 20.04 Laptop

Running Ubuntu on Laptop? Here’s the beginner’s guide shows how to configure and tell what to do when the lid is closed.

By default Ubuntu will go suspend when you close the laptop lid. There’s no option to change this action since the relevant settings in Dconf Editor do not work.

What if you want your machine go to sleep, power off, hibernate, or just do nothing when you close the laptop lid? Well, you can do this by changing the configuration file for the systemd-logind service.

1. Edit the systemd-logind config file:

Firstly open terminal by either pressing Ctrl+Alt+T on keyboard, or searching from ‘Activities’ overview. When it opens, run command to edit the config file:

sudo -H gedit /etc/systemd/logind.conf
For Ubuntu 22.10, replace gedit with gnome-text-editor. Or, just use nano instead if you don't know your system default text editor.

About the key lines:

Remove ‘#‘ at the beginning to enable the line, and change the value!

  • HandleLidSwitchDocked=ignore – If your system is inserted in a docking station, or if more than one display is connected, then the action occurs if specified.
  • HandleLidSwitchExternalPower=suspend – If your system is on external power, the action occurs if specified.
  • HandleLidSwitch=suspend – For all other cases, the value of HandleLidSwitch will occur if enabled.

About the key values:

The value for the lid close behavior can be:

  • ignore – do nothing.
  • poweroff – shutdown machine.
  • reboot – restart the system.
  • lock – screen lock all running sessions.

You can also set the value to suspend, hibernate (make sure if hibernate works firstly), halt, hybrid-sleep (save system state to both disk & RAM), suspend-then-hibernate, or even kexec system call.

2. To make things simple:

To change lid close action without any condition, enable (remove ‘#’) the #HandleLidSwitch=suspend line and change the value to ‘ignore‘, ‘lock‘, ‘poweroff‘, etc.

Читайте также:  Линукс создать точку монтирования

To tell Ubuntu what to do when your notebook plugged, also remove # from #HandleLidSwitchExternalPower=suspend line and change its value.

For multi-display or dock station, remove # from #HandleLidSwitchDocked=ignore to enable it and set a value.

3. Apply changes:

After changes, save the file and restart the logind service by running command in terminal:

systemctl restart systemd-logind.service
SAVE YOUR WORK before running the command as it will log out the current session.

Источник

How to Change Laptop Lid Close Action in Ubuntu Linux

This post describes steps one can take to set laptop lid close behavior to ignore if the laptop lid or screen is closed in Ubuntu Linux.

Ubuntu Linux is configured to automatically suspend when the laptop lid is closed to save power. This feature has always been part of the Ubuntu Linux platform but is relatively easy to disable, so when you close the laptop screen or lid, it doesn’t sleep.

When Ubuntu Linux goes to suspend mode, it’s not turned off – go to sleep. Then, you can resume by opening the lid, and your session will continue from where you left off.

When the action is set to ignore, you can close the lid without putting the laptop to sleep while work is still being done.

How to keep the laptop on when the screen is closed in Ubuntu Linux

As described above, Ubuntu Linux will automatically suspend when you close the laptop lid to save power. You can change that so it doesn’t sleep; below is how to do that.

To stop Ubuntu Linux from suspending when the lid is closed, follow these steps:

These instructions will only work if you are using systemd.

First, press the CTRL + ALT + T keyboard shortcut to open the command console terminal.

sudo gedit /etc/systemd/logind.conf

Once the file opens, search for the line below:

#HandleLidSwitch=suspend

HandleLidSwitch=ignore

Next, run the commands below to apply your changes.

sudo systemctl restart systemd-logind.service

Finally, you can restart your computer and test it to see if it works.

Alternatively, install Gnome Tweaks to help you control laptop lid close behavior in Ubuntu Linux.

Run the commands below to install.

sudo apt install gnome-tweaks

After installing the app, go to the Activities overview and search for Tweaks.

In the app, under General, toggle the switch to Off for Suspend when the laptop lid is closed.

This post showed you how to configure Ubuntu Linux so that it doesn’t go to sleep when the laptop lid or screen is closed. If you find any error above or have something to add, please use the comment form below to report.

Richard W

I love computers; maybe way too much. What I learned I try to share at geekrewind.com.

Источник

Оцените статью
Adblock
detector