I'm using a Linux (RHEL6) workstation. I have a small script I wrote which locks and unlocks the screen via xscreensaver when I connect or disconnect my USB thumb drive, which effectively turns it into a physical key to my workstation. The problem is that there doesn't seem to be a good way to unlock xscreensaver from the command line. xscreensaver-command -deactivate, counterintuitively, only "simulates user activity" and still requires a password to unlock the screen. xscreensaver-command -exit only kills the parent daemon xscreensaver if there is not a screensaver running. As the man page for xscreensaver-command -exit warns,
Warning: never use kill -9 with xscreensaver while the screensaver is active. If you are using a virtual root window manager,
that can leave things in an inconsistent state, and you may need to restart your window manager to repair the damage.
Indeed, I am currently using pkill xscreensaver as my method to get rid of the screensaver from a script, which often results in zombie processes and other messes. How can I unlock the screensaver safely from a script/the command line?