both of these only work after the screen that was locked gets blanked; but they sometimes fail also, when for any reason the screen doesnt blanks...
gnome-screensaver-command --query
gnome-screensaver-command --time
I tried with qdbus
also:
qdbus org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.GetActiveTime
but it equally failed.
I just found that who actually locks the screen is Unity!
qdbus com.canonical.Unity /com/canonical/Unity/Session com.canonical.Unity.Session.Lock
Related questions:
https://unix.stackexchange.com/questions/28181/run-script-on-screen-lock-unlock
https://unix.stackexchange.com/questions/80143/how-to-create-a-daemon-which-would-be-listening-to-dbus-and-fire-script-on-messa