Skip to main content
10 of 13
execution of the external script after unlock is not yet relevant

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 manage_session_locker.sh script :

#!/bin/bash # Manage the locker of 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 is missing in the return of loginctl # - locked when lightdm is present in the return of loginctl # Here the session is unlocked # ... (what to do before locking) # Lock before continue (here the command may vary) light-locker-command --lock # Here the session is locked # ... (what to do after locking) 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 # ... (what to do after locking) 

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 "manage_session_locker.sh" 

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

The word of end : with Debian 11, 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. In this case to use a script with spaces in its name we can escape them with '' prepended. This behavior seems different with Debian 12 with XFCE4 DE (v4.18)