I found another solution to achieve it under Debian 12 with XFCE4 DE (v4.18).
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 :
user@host:~$ xfconf-query -c xfce4-session -p /general/LockCommand \ --set "touch \$HOME/Desktop/touched" user@host:~$ xfconf-query -c xfce4-session -p /general/LockCommand -lv /general/LockCommand touch $HOME/Desktop/touched ... and tried to lock my session then the touched file is created on my desktop.
Then I elaborated the wait_for_unlock.sh script :
#!/bin/bash # Script to wait the unlock session (make this script executable). # Usage : # ./wait_for_unlock.sh /the/script/to/execute/after/unlocking # 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 (here the command may vary) 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 # Execute after unlocking $1 Note : the delay of sleep can be increased to let the system more often idled but not exaggerated because we possibly will wait this maximum time to get the control after unlocking
Then we had to replace the current value of LockCommand property, and in my case :
xfconf-query -c xfce4-session -p /general/LockCommand \ --set "wait_for_unlock.sh execute_on_unlock.sh" And in the execute_on_unlock.sh script I wrote all I want to do when the session is unlocked (reminder script must be executable).
Note : to undo this modification use xfconf-query -c xfce4-session -p /general/LockCommand -r
The word of end : I discovered that the --set parameter of xfconf-query must not embed inner quotes in any case nor multiple command (i.e. CMD1 ; CMD2) because the if statement will considers an empty string then apart modifying the xflock4 script (see above) which will be replaced in the next upgrade we must use one script with different not quoted delimited parameters.