[GTALUG] Locking KDE 5 screen from shell script

Lennart Sorensen lsorense at csclub.uwaterloo.ca
Wed Aug 12 15:31:15 UTC 2015


On Wed, Aug 12, 2015 at 03:21:41AM -0400, Randy Jonasz wrote:
> I recently installed kde5 on debian stretch.  I have a yubikey which I use
> to log in with.  I'd like to lock the screen when I remove the yubikey.  I
> have it working with cinnamon and lxde but I can't quite get it with kde.  I
> can lock the screen if I run the shell script from a terminal as root but
> when I remove the yubikey the shell script returns error code 1.
> 
> Here's my shell scripts:
> 
> ykgone.sh
> 
> Konsole output
> #! /bin/sh
> if [ -z "$(lsusb | grep Yubikey)" ] ; then
>        if [ ! -z "$(ps aux | grep cinnamon-session | grep -v grep)" ] ; then
>                /bin/su rjonasz -c "DISPLAY=:0 cinnamon-screensaver-command
> -l"
>        elif [ ! -z "$(ps aux | grep startkde | grep -v grep)" ] ; then
>                /usr/bin/sudo -u rjonasz -H -i  /usr/local/bin/lockkde.sh
>        else
>                /bin/su rjonasz -c "DISPLAY=:0 xscreensaver-command --lock"
>        fi
> fi
> 
> 
> lockkde.sh
> 
> Konsole output
> #! /bin/sh
> 
> kde_pid=`pidof kdeinit5`
> export `cat /proc/$kde_pid/environ|grep -ao
> 'DBUS_SESSION_BUS_ADDRESS=[[:graph:]]*'`
> /usr/bin/qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock
> 
> 
> I can't seem to figure this one out.

Are you sure the PATH is set the same when run from a terminal versus
when run by your key being removed?

Try for debugging to do at the start of the script:

echo $PATH > /tmp/$$.path.env

Then after running it both ways you should have a file for each PID that
did it that you can compare.

-- 
Len Sorensen


More information about the talk mailing list