How to execute a script when xfce session ends

See http://mail.xfce.org/pipermail/xfce/2012-November/031694.html - There, Erik Habicht suggested creating a wrapper script in /usr/local/bin/xfce4-session (or another dir that precedes the dir where xfce4-session is installed, /usr/bin in your PATH). This way, you do not have to change /usr/bin/X11/xfce4-session, so it can be updated independently.

#!/bin/bash
# Add your own pre-session logic here
/usr/bin/xfce4-session
# Add your own logout logic here

then

$ chmod +x /usr/local/bin/xfce4-session

It's not perfect (depends on PATH order) but may be more palatable.

(Note: I promoted my comment to an answer.)


Change the /usr/bin/xfce4-session executable with a shell script which runs the original xfce4-session and your logout script if xfce4-session finished.

# mv /usr/bin/xfce4-session /usr/bin/xfce4-session.orig

The new /usr/bin/xfce4-session file:

#!/bin/bash
/usr/bin/xfce4-session.orig
echo "my logout script" > /tmp/testfile

Don't forget to set the execute permissions:

# chmod a+x /usr/bin/xfce4-session

(Tested on Debian Squeeze.)

Tags:

Linux

Xfce