My system (Ubuntu 15.10) has a bug: I have enabled "Require my password when waking from suspend" on the "Brightness & Lock" settings panel, but it does NOT ask for my password, which is incredibly insecure.
As a workaround, I'm trying to write a script which will live under /etc/pm/sleep.d
. It should be something like this:
#!/bin/bash
case "${1}" in
hibernate)
# Do nothing
;;
resume|thaw)
su -c "gnome-screensaver-command --lock" MYUSERNAME
;;
esac
Problem is, this doesn't work; the gnome-screensaver-command
fails with the following message:
** Message: Failed to get session bus: Could not connect: Connection refused
Then, I tried to change the command to:
su MYUSERNAME -c "export $(dbus-launch) && gnome-screensaver-command -l"
Which then fails with:
** Message: Failed to get session bus: The connection is closed
So, the question is: what would be the right way to do this?