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
while [ 1 ]
grep closed /proc/acpi/button/lid/LID/state && pmi action suspend
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.