How to execute a script when xfce session ends

Denis R. picture Denis R. · Sep 28, 2011 · Viewed 8.4k times · Source

Is it possible to run a script/command when the xfce session stops ?

Answer

djb picture djb · Aug 12, 2013

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.)