Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So when i hibernate my laptop the screen doesn't lock automatically. To solve this i've changed /etc/acpi/ to contain:

su - myUsername -c "gnome-screensaver-command -l"
sudo pm-hibernate
exit 0

When running this file from a command line it works as intended (ie, lock the screen and then hibernate). Unfortunately, when pressing the power button, it still just hibernates without locking the screen -what am I missing?

EDIT: I've added the line whoami>>~/Desktop/test.txt to verify which user is executing the /etc/acpi/powerbtn.shscript. When pressing the power button, the file test.txt is created, but is empty. From this i conclude that the script is in fact being called when pressing the power button. What i do not understand is how the output of whoami can be empty...

share|improve this question

I suppose gnome-screensaver-command needs to know the DISPLAY variable you are using. Since (in theory) multiple users can be logged in on one computer (also graphically), it needs to know whose display(s) to lock. The first one is ":0". Try

su - myUsername -c "DISPLAY=:0 gnome-screensaver-command -l"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.