Skip to main content
4 of 13
test utile en fait

I found another solution to achieve it under Debian 12 with XFCE4 DE.

xflock4 is the command I use to lock the session.

In fact it is a script (discovered by file $( which xflock4 )) which contains :

... # First test for the command set in the session's xfconf channel LOCK_CMD=$(xfconf-query -c xfce4-session -p /general/LockCommand) if [ -n "$LOCK_CMD" ]; then /bin/sh -c "$LOCK_CMD" && exit exit_code=$? >&2 printf "'%s' exited with status %d\n" "$LOCK_CMD" $exit_code exit $exit_code fi ... 

I saw that the /bin/sh -c "$LOCK_CMD" is executed only if the LockCommand property is not empty.

I tried :

user@host:~$ xfconf-query -c xfce4-session -p /general/LockCommand -lv /general/LockCommand 

... and discovered its value is empty in my case then it executes the remaining code which basically tests all locker's applications to apply a lock.

Then I tried to add a value to test it :

xfconf-query -c xfce4-session -p /general/LockCommand \ -s "touch \$HOME/Bureau/touched ; light-locker-command --lock" 

Note : light-locker is my locker's application

And it worked, as the file touched is created on my desktop before locking.


Then I elaborated the wait_for_unlock.sh script :

#!/bin/bash # Script to wait the unlock session (make this script executable). # Note : `loginctl list-sessions --no-legend | grep -c lightdm` # is my solution to determine when the session is locked ; # it was found by tries and is probably not the better solution # - # Observed : # - unlocked when lightdm output is missing # - locked when lightdm output is present # Here the session is unlocked # Lock before continue light-locker-command --lock # Here the session is locked while [ 1 ] ; do is_locked=$( loginctl list-sessions --no-legend \ | grep -c lightdm ) if [[ $is_locked -eq 0 ]] ; then break fi sleep 0.1s done # Here the session is unlocked again 

Note : the delay of sleep can be increased to let the system more often idled but not exaggerated because we will wait this maximum time to get the control before unlock

Then we had to replace the current value of LockCommand property, and in my case :

xfconf-query -c xfce4-session -p /general/LockCommand \ -s "execute_on_lock.sh ; wait_for_unlock.sh ; execute_on_unlock.sh" 

And in the execute_on_lock.sh script I wrote all I want to do when the session is locked, and in the execute_on_unlock.sh script I wrote all I want to do when the session is unlocked (reminder scripts must be both executable).

Note : to undo this modification use xfconf-query -c xfce4-session -p /general/LockCommand -r