Ubuntu – Unlock gnome-screensaver instead of deactivating

gnomelock-screenscreensaverusb

So, I've been trying to create a USB key for my machine.

I've used PAM-Usb as described in many places over the internet (for example this one, which is basically copypasted everywhere).
I understand what happens there and thats pretty neat.

My problem is – if I lock screen (with button, plugging USB off or with gnome-screensaver-command -l), then gnome-screensaver-command -d won't bring me back to my desktop, but rather wakes up the monitor. I still have to provide password – and I don't want that when I plug USB stick in.

I don't want to turn off password prompt at unlock. I want my computer freely accessible at any given moment when USB stick is plugged in and accessible with password in other case.

So, the question is: how do I unlock gnome-screensaver with a command line?

PS. Funny thing: if I use a USB key, then I don't have to provide password when logging in. On the other hand, on unlock it is needed. I understand why it happens, but still, it looks weird.

==EDIT==

I forgot: I'm using plain (meaning Unity-based) Ubuntu 15.04. No screensaver-related modifications were made.

Best Answer

Ubuntu 14.04+ no longer uses gnome-screensaver, that's why gnome-screensaver-command -d may not work (probably, I'm not sure, but Ubuntu has replaced the old gnome-screensaver with something new and that command doesn't work currently). You can lock and unlock your computer using dbus.

Lock:

dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock

Unlock:

dbus-send --session --dest=org.gnome.ScreenSaver --type=method_call --print-reply --reply-timeout=20000 /org/gnome/ScreenSaver org.gnome.ScreenSaver.SetActive boolean:false

It should unlock without asking for password.