Make Ubuntu 12.1 suspend on lid close (HP and Dell laptops)

linux

The latest quirk in my new Ubuntu system has been a certain unwillingness for my laptop to suspend when the lid is closed. Instead of bedding down to a restful night of counting electric sheep, the poor thing just stays awake, processing and whatnot. I was able to find a bash script that allowed me to put a button on my task bar that I could click to put the computer into suspend. But that’s an extra click. And not very slick.

So I dug around some more. I tried various solutions, such as the obvious commands in the system settings, editing some of the system files, and trying out TuxOnIce (a program that gives greater control over the suspend/hibernate functions), but to no avail. The more I read, the more disheartened I became. This problem of mine is pretty common (with both Dell and HP laptops), and there doesn’t seem to be an apparent solution.

I got to thinking. I already made this button that initiates suspend- why not take that same script and change it a bit so that it’ll automatically execute itself when the lid is closed? It’s not the most elegant of solutions, but it’s no-fuss and happens in the background without my having to to anything.

More googling ensued and I found this page that provides a bash script for doing this very thing. However, looking at it, I knew it wouldn’t work for me off-the-rack. My system, for whatever reason, won’t recognize the “sudo-pm suspend” command. But it will work with the “pmi action suspend” command I found in the forum post that explained how to use the suspend script I had success with previously. So I combined them:

#ensures that a closed lid causes the computer to suspend
#! /bin/bash

while [ 1 ]
do
sleep 20
grep closed /proc/acpi/button/lid/LID/state && pmi action suspend
done

To use this, you simply create a new file and name it something (like suspend_on_lid_close). You open the file and paste the above script into it. Save and close. Right click the file and select “properties.” Click on the “Permissions” tab and check the box that says “Allow executing file as program.” From there, go to the “settings” icon in the upper corner of the screen and select “Startup Applications” from the menu. Click the “Add” button, name it “Suspend on lid close” (or something) and click the “browse” button. Navigate to your freshly created file and click “close.” Reboot your system and you should be good to go.

If you’re at your wits’ end like I was, this little script will be a godsend.

Advertisements

2 thoughts on “Make Ubuntu 12.1 suspend on lid close (HP and Dell laptops)

  1. am coming to you from now on for my problems. That was pretty neat. Last night my laptop just decided not to suspend unless chosen at a menu. Arg! And lo and behold the Linux Gods shone on my system and it started to work on its own. I now believe in miracles.

    1. Ha. Thanks, Johnny.

      The suspend function on laptops is horribly frustrating. I hope it’s something they pay more attention to in the future. It’s cool that the installation automatically detects that it’s going onto a laptop, but those features just don’t work as they should. I’m glad to hear yours started miraculously working. The same thing happened to me the other day when all of the letter e’s just disappeared from my Ubuntu menus. Strangest thing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s